Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

WaveformPlot.HistoryCapacity causes memory leak

I have made a program that repeatedly clears out and creates waveform plots on a WaveformGraph. When I set the HistoryCapacity value to a large number I have noticed that the memory taken by the plots isn't freed when the plots are cleared. I want to log values with a rate of 100 samples / second. With the HistoryCapacity set to 300000 (= 50 minutes) my free RAM decreases with about 3 Mb for each plot line. Eventually all RAM has been used and I get a Out of memory exception.
 
 
0 Kudos
Message 1 of 2
(3,412 Views)
I made an example program that illustrates my problem. It is a Windows Form with three knobs, a Reload button, a Start/stop button, a timer, a WaveformGraph and a Legend.
The Start/stop button will start logging values from the three knobs in the graph. The Reload button will clear out the plots from the graph, add three new plots to the graph and set some properties.
 
When clicking the Reload button repeatedly and monitoring the RAM in the Task Manager, you can see that the memory usage increases all the time. No memory is released, not even when I force the garbage collection.
 
Here is the code:

private void cmdReload_Click(object sender, System.EventArgs e)
{
 Graph.Plots.Clear();
 Legend.Items.Clear();

 GC.Collect();
 GC.WaitForPendingFinalizers();

 AddLine(knob1, Color.Red);
 AddLine(knob2, Color.Blue);
 AddLine(knob3, Color.Green);
}

private void AddLine(Knob k, Color c)
{
 WaveformPlot w = new WaveformPlot();
 w.XAxis = Graph.XAxes[0];
 w.YAxis = Graph.YAxes[0];
 w.LineColor = c;
 w.HistoryCapacity = 300000;
 w.LineStyle = LineStyle.Solid;
 w.LineWidth = 2;
 w.Tag = k;

 Graph.Plots.Add(w);

 LegendItem li = new LegendItem(w, k.Caption);
 Legend.Items.Add(li);
}

private void cmdStart_Click(object sender, System.EventArgs e)
{
 timer1.Enabled = !timer1.Enabled;
}

private void timer1_Tick(object sender, System.EventArgs e)
{
 Graph.Plots[0].PlotYAppend(knob1.Value);
 Graph.Plots[1].PlotYAppend(knob2.Value);
 Graph.Plots[2].PlotYAppend(knob3.Value);
}

0 Kudos
Message 2 of 2
(3,409 Views)