Completed
Last Updated: 12 Jun 2014 11:35 by Chris Ward
ADMIN
George
Created on: 05 May 2014 07:03
Category: ChartView
Type: Bug Report
2
FIX. RadChartView - Memory leak when clearing the Series collection and re-adding another Series
To reproduce:

Have a RadButton and a RadChartView on a form. On button click use the following code:
private void GenerateSeries()
{
    LineSeries lineSeries = new LineSeries();
    lineSeries.DataPoints.Add(new CategoricalDataPoint(20, "Jan") { Label = "January" });
    lineSeries.DataPoints.Add(new CategoricalDataPoint(22, "Apr"));
    lineSeries.DataPoints.Add(new CategoricalDataPoint(12, "Jul"));
    lineSeries.DataPoints.Add(new CategoricalDataPoint(19, "Oct"));
    lineSeries.LegendTitle = "Line 1 ";
    this.Chart.Series.Add(lineSeries);
    lineSeries.BackColor = Color.Black;
    lineSeries.PointSize = new SizeF(15, 15);

    LineSeries lineSeries2 = new LineSeries();
    lineSeries2.DataPoints.Add(new CategoricalDataPoint(18, "Jan"));
    lineSeries2.DataPoints.Add(new CategoricalDataPoint(15, "Apr"));
    lineSeries2.DataPoints.Add(new CategoricalDataPoint(17, "Jul"));
    lineSeries2.DataPoints.Add(new CategoricalDataPoint(22, "Oct"));

    lineSeries2.LegendTitle = "Line 2 ";
    this.Chart.Series.Add(lineSeries2);
}

void RadButton_Click(object sender, EventArgs e)
{
    this.Chart.Series.Clear();
    this.GenerateSeries();
}


You will notice that the memory will not decrease after a few presses of the button.

Workaround:

Set the Provider of the LegendElement to null:

private void GenerateSeries()
{
    this.Chart.ChartElement.LegendElement.Provider = null;


    LineSeries lineSeries = new LineSeries();
    lineSeries.DataPoints.Add(new CategoricalDataPoint(20, "Jan") { Label = "January" });
    lineSeries.DataPoints.Add(new CategoricalDataPoint(22, "Apr"));
    lineSeries.DataPoints.Add(new CategoricalDataPoint(12, "Jul"));
    lineSeries.DataPoints.Add(new CategoricalDataPoint(19, "Oct"));
    lineSeries.LegendTitle = "Line 1 ";
    this.Chart.Series.Add(lineSeries);
    lineSeries.BackColor = Color.Black;
    lineSeries.PointSize = new SizeF(15, 15);

    LineSeries lineSeries2 = new LineSeries();
    lineSeries2.DataPoints.Add(new CategoricalDataPoint(18, "Jan"));
    lineSeries2.DataPoints.Add(new CategoricalDataPoint(15, "Apr"));
    lineSeries2.DataPoints.Add(new CategoricalDataPoint(17, "Jul"));
    lineSeries2.DataPoints.Add(new CategoricalDataPoint(22, "Oct"));

    lineSeries2.LegendTitle = "Line 2 ";
    this.Chart.Series.Add(lineSeries2);
}

void Button_Click(object sender, EventArgs e)
{
    this.Chart.Series.Clear();
    this.GenerateSeries();
}
1 comment
Chris Ward
Posted on: 29 May 2014 21:23
Wow, this is a serious issue. I've been trying to fix this for hours. Thank you SO much for the work around!