This is a migrated thread and some comments may be shown as answers.

Memory leak in Grid hierarchy template

5 Answers 178 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Kun
Top achievements
Rank 2
Kun asked on 15 Apr 2019, 10:58 AM

Hello,

My gridview bounds with two data collections. One collection bounds to the master template, the other bounds to the template in the master template.

I've found the memory leak during the hierarchy templates refresh.

I made a simple demo. Please download it from:

https://www.dropbox.com/s/btzb5go8e4bnrmk/RefreshHierarchy.rar?dl=0

In the demo, there are two data collections. If I refresh 50 elements in each collections, the memory will leak very fast. Please see the memory diagnosis trace in the attached photos.

If I collapse all hierarchy template, only refresh the master template, the memory maintains well.

Thank you by advanced for your support.

Regards,

5 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 16 Apr 2019, 10:04 AM
Hi Kun,

Please note that the garbage collector is non-deterministic and you cannot be sure when it will be executed. In order to properly test this, you need to force the garbage collector after the form is closed. When this is done the memory levels are restored (see attached). I have attached a modified version of the test project as well.

Should you have any other questions do not hesitate to ask.
 
Regards,
Dimitar
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Kun
Top achievements
Rank 2
answered on 16 Apr 2019, 10:42 AM

Hello Dimitar,

Thank you for your reply.

Actually, the grid form is my main form. It will be closed only if the user closes the software.

I've add a timer of GC collector in your demo. The refresh timer is triggered every second, the GC timer is triggered every 2 seconds.

private void Timer2_Tick(object sender, EventArgs e)
        {
            Console.WriteLine("GC recycle");
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.WaitForFullGCApproach();
            GC.WaitForFullGCComplete();
            GC.Collect();
        }

 

The memory seems to be leaking more slowly, but there is still a leak.

Please see memory trace in the attached photo.

I don't understand why the memory maintains well only if the master template refreshes. With the hierarchy template, the memory can't stop leaking.

 

Thank you by advance for your help.

Regards,

 

0
Dimitar
Telerik team
answered on 17 Apr 2019, 10:28 AM
Hello Kun,

While the grid is being updated and visible there are a lot of internal objects that are used and updated. This is why the memory consumption is not a reliable indicator when the grid is constantly updated. Nevertheless, I can suggest encapsulating the updated operation within BeginUpdate\EndUpdate block. When EndUpdate is called the grid data will be reset at once which will release the objects held by the grid and this way the update works even faster:
private void timer1_Tick(object sender, EventArgs e)
{
    radGridView1.BeginUpdate();
 
    childList.Clear();
    masterList.Clear();
 
    for (int i = 0; i < 10; i++)
    {
        masterList.Add(new MasterObject(Guid.NewGuid().ToString(), i + ".Title"));
    }
 
    Random rand = new Random();
    for (int i = 0; i < 5; i++)
    {
        childList.Add(new ChildObject(i, i + ".Name", masterList[rand.Next(0, masterList.Count)].UniqueIdentifier));
    }
 
    radGridView1.EndUpdate();
 
    foreach (GridViewRowInfo row in radGridView1.Rows)
    {
        row.IsExpanded = true;
    }
}

With this approach, I am getting a steady memory consumption. Could you please try it and let me know the results on your side. 

I am looking forward to your reply.

Regards,
Dimitar
Progress Telerik
Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Kun
Top achievements
Rank 2
answered on 17 Apr 2019, 04:10 PM

Hello Dimitar,

Thank you for your solution. It works better. But the memory still leaks. With 50 random elements in master template, and 10 random elements in hierarchical template (all expanded), the memory increases about 1M per minute in the demo by using the refresh every second and the GC.collect routine every 2 seconds. Imagine keeping the program running for a day....

I've done some tests and I've found out :

If refresh only the master template, the memory is steady. After I expanded all child templates, the memory will increase heavily (it's normal.). And also I can see the gridview control does lots of GC collect. Part of the memory resource is recycled. But globally, the memory increases.

And then, if I collapse all child templates, keep only the master template refreshing. The memory cannot go back to the level at the first place. But it remains stable.

Please explain this behavior.

 

Thank you by advance.

Regards,

0
Dimitar
Telerik team
answered on 18 Apr 2019, 08:22 AM
Hello Kun,

I have looked at this again and there is indded a small constant memory incerease after a the grid is updated more often. I have logged this so our developers can investigate it and determine what is casing this. You can track its progress, subscribe to status changes and add your comment to it here. I have also updated your Telerik Points.

Currently I cannot sugest a workaround other than restarting the enitre form when the memory consuption is critical.

Should you have any other questions do not hesitate to ask.
 
Regards,
Dimitar
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
Kun
Top achievements
Rank 2
Answers by
Dimitar
Telerik team
Kun
Top achievements
Rank 2
Share this question
or