Completed
Last Updated: 06 Mar 2017 08:35 by ADMIN
ADMIN
Dimitar
Created on: 24 Sep 2015 12:42
Category: ChartView
Type: Bug Report
0
FIX. RadChartView - memory leak when the axis labels are changed constantly.
To reproduce:
public RadForm1()
{
    InitializeComponent();
    date = DateTime.Now;
}
int dayCounter;
Random rnd = new Random();
DateTime date;


Timer timer = new Timer();
protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
    LineSeries lineSeria = new LineSeries();
    DateTimeContinuousAxis continuousAxis = new DateTimeContinuousAxis();          
    continuousAxis.LabelFormat = "{0:dd}";
    lineSeria.HorizontalAxis = continuousAxis;
    radChartView1.Series.Add(lineSeria);

    for (int i = 0; i < 500; i++)
    {
        radChartView1.Series[0].DataPoints.Add(new CategoricalDataPoint(rnd.Next(1000), date.AddDays(dayCounter++)));
    }

    timer.Tick += timer_Tick;
    timer.Interval = 200;
    timer.Start();
}

void timer_Tick(object sender, EventArgs e)
{
    foreach (CategoricalDataPoint point in radChartView1.Series[0].DataPoints)
    {
       // point.Value = rnd.Next(1000);
        point.Category = date.AddDays(dayCounter++);
    }
}

Workaround:
void timer_Tick(object sender, EventArgs e)
{
    DateTimeContinuousAxis continuousAxis = ((LineSeries)radChartView1.Series[0]).HorizontalAxis as DateTimeContinuousAxis;

    HybridDictionary hashSet = typeof(Axis).GetField("hashSet", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(continuousAxis) as HybridDictionary;
    hashSet.Clear();

}

(Total attached files size should be smaller than 20mb. Allowed extensions: .zip, .rar, .jpg, .png, .gif)
1 comment
ADMIN
Ralitsa
Posted on: 06 Mar 2017 08:35
Our investigation of this case concluded that actually, this is not a memory leak - this is element caching. 
The Axis caches each visual element and then it is being reused when a new paint cycle occurs. In the client's scenario a new point with unique value/category is created on timer tick. In this case the elements are cached, but are not reused and this is why this looks like a memory leak. 

In order to prevent such behavior when changing axis labels constantly, you can set the EnableElementCache property of the axis to false or continue to use the suggested workaround.