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

BeginUpdate, EndUpdate – meam leak becasue of event ThemeNameChanged.

4 Answers 275 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Raymond
Top achievements
Rank 1
Raymond asked on 16 Mar 2011, 11:53 AM

Hi

 

Users of my app some time ago reported issue with memory leak, so I started investigation and it looks that there is problem with RadGridView.

 

 

This is my sample code:

 

 

 

public partial class Form1 : Form
{
    BindingList<Package> _packages = new BindingList<Package>();
    BindingList<PackageItem> _items = new BindingList<PackageItem>();
    public Form1()
    {
        InitializeComponent();
        radGridView1.DataSource = _packages;
        radGridView1.ReadOnly = true;       
     
        GridViewTemplate viewItemsTemplate = new GridViewTemplate();
        viewItemsTemplate.DataSource = _items;
        this.radGridView1.MasterTemplate.Templates.Add(viewItemsTemplate);
 
        GridViewRelation relation = new GridViewRelation(radGridView1.MasterTemplate);
        relation.RelationName = "myRelation";
        relation.ChildTemplate = viewItemsTemplate;

        relation.ParentColumnNames.Add("Id");
        relation.ChildColumnNames.Add("PackageId");

        this.radGridView1.Relations.Add(relation);
        _packages.Add(new Package() { Id = "1", Name = "Package1" });
        _items.Add(new PackageItem() { Id = "1", PackageId = "1", Name = "Item1 in package1" });
        _items.Add(new PackageItem() { Id = "2", PackageId = "1", Name = "Item2 in package1" });
        _packages.Add(new Package() { Id = "2", Name = "Package2" });
        _items.Add(new PackageItem() { Id = "3", PackageId = "2", Name = "Item1 in package2" });
        _items.Add(new PackageItem() { Id = "4", PackageId = "2", Name = "Item2 in package2" });
        radGridView1.BestFitColumns();
    }
    private void btnDelete_Click(object sender, EventArgs e)
    {
        radGridView1.BeginUpdate();
        PackageItem pi = _items[0];
        _items.Remove(pi);
        radGridView1.EndUpdate();
    }
}

 

 

 

 

 

 

 

When I delete row I call BeingUpdate() and EndUpdate(), this is needed – without these calls row is not deleted and after click on row exception is thrown.

 

The problem for sure is missing unhooking event RadGridView.ThemeNameChanged (I do not know if there are other missing unhooks).

 

 

 

TO SEE this problem before deleting row YOU HAVE TO expand child rows!

 

 

I used profiler and I have seen that there are types that hook this event and do not unhook after disposing! These types are: GridDetailViewCellElement, GridDetailViewRowElement, GridTableElement. You can check details in screen shots.

How can I solve this problem? This is really urgent issue for me – I have a lot of updates in my grid and after couple hours there is always out of memory exception caused by my app.

Regards

 

 

4 Answers, 1 is accepted

Sort by
0
Raymond
Top achievements
Rank 1
answered on 16 Mar 2011, 12:28 PM
I reported this as a bug: Bug Report ID:403813
0
Raymond
Top achievements
Rank 1
answered on 16 Mar 2011, 01:46 PM
I have just checked that those three types (GridDetailViewCellElement, GridDetailViewRowElement, GridTableElement) also do not unhook event MasterGridViewTemplate.PropertyChanged.
0
Raymond
Top achievements
Rank 1
answered on 16 Mar 2011, 03:29 PM
ok this is not a bug, my code was wrong, this is solution for this problem:

radGridView1.MasterTemplate.Templates[0].BeginUpdate();
  
 PackageItem pi = _items[0];
        _items.Remove(pi);
  
radGridView1.MasterTemplate.Templates[0].EndUpdate();
0
Jack
Telerik team
answered on 21 Mar 2011, 05:27 PM
Hi Raymond, 

I am glad that you have found a solution for this issue. Should you have any further questions, do not hesitate to contact us.

Greetings,
Jack
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
GridView
Asked by
Raymond
Top achievements
Rank 1
Answers by
Raymond
Top achievements
Rank 1
Jack
Telerik team
Share this question
or