Completed
Last Updated: 28 Oct 2014 16:06 by Moe
ADMIN
Dimitar
Created on: 30 Sep 2014 11:47
Category: PropertyGrid
Type: Bug Report
0
FIX. RadPropertyGrid - Memory leak - the control keep references to some events which prevents proper disposing.
To reproduce:
- Add 20 document windows that contain property grid to a dock (use RadTextBox for he grid's selected object).
- Close and dispose the windows.
- The memory is not properly released.
1 comment
Moe
Posted on: 28 Oct 2014 16:06
I found a work around to this issue. Setting the SelectedObject to null did not free the memory. I had to walk through PropertyGrid items, and setting the DataBoundItem to null. 
Sharing the code just incase someone need it.

if (radPropertyGrid1 != null)
			{

				this.comboBox1.SelectedIndexChanged -= new System.EventHandler(this.comboBox1_SelectedIndexChanged);

				//loopthroug all the grid item and dispose them
				foreach (var item in radPropertyGrid1.Items)
				{
					item.DataBoundItem = null;

					IDisposable original = ((Telerik.WinControls.UI.PropertyGridItem)(item)).OriginalValue as IDisposable;
					if (original != null)
						original.Dispose();

					IDisposable instance = ((Telerik.WinControls.UI.PropertyGridItem)(item)).Instance as IDisposable;
					if (instance != null)
						instance.Dispose();

					IDisposable value = ((Telerik.WinControls.UI.PropertyGridItem)(item)).Value as IDisposable;
					if (value != null)
						value.Dispose();

				}

				if (radPropertyGrid1.SelectedObject != null)
				{
					((IDisposable)radPropertyGrid1.SelectedObject).Dispose();
					radPropertyGrid1.SelectedObject = null;
				}
				this.radPropertyGrid1.EditorInitialized -= new PropertyGridItemEditorInitializedEventHandler(radPropertyGrid1_EditorInitialized);
				this.radPropertyGrid1.EditorRequired -= new PropertyGridEditorRequiredEventHandler(radPropertyGrid1_EditorRequired);

				if (this.radPropertyGrid1.RadContextMenu != null)
				{
					this.radPropertyGrid1.RadContextMenu.DropDownOpening -= RadContextMenu_DropDownOpening;
					this.radPropertyGrid1.RadContextMenu.DropDownClosing -= RadContextMenu_DropDownClosing;
					this.radPropertyGrid1.RadContextMenu.Dispose();
					this.radPropertyGrid1.RadContextMenu = null;
				}

				

				if (this.radPropertyGrid1.PropertyGridElement != null)
				{
					this.radPropertyGrid1.PropertyGridElement.DisposeChildren();
					this.radPropertyGrid1.PropertyGridElement.Dispose();
				}
				if (this.radPropertyGrid1.PropertyGridElement.PropertyTableElement != null)
				{
					this.radPropertyGrid1.PropertyGridElement.PropertyTableElement.DisposeChildren();
					this.radPropertyGrid1.PropertyGridElement.PropertyTableElement.Dispose();
				}

				radPropertyGrid1.Dispose();
				this.radPropertyGrid1 = null;
			}