Page 1 of 1

ContextMenuStrip issue

Posted: Fri Dec 11, 2009 5:58 pm
I have a simple project that has two forms, the parent mdi form and the child mdi form. The only control on the parent form is a button that opens the child form. The only control on the child form is a ContextMenuStrip. If I start the program, click the button to open the child form and close the child form and take a snapshot, I see that the child form, ContextMenuStrip, ToolStripGrip and ToolStripControlButton.StickyLabel have all been Disposed but not GC's.

The child form also still appears to be in memory.

In the root path for the ContextMenuStrip I see that is is referenced by PropertyStore.ObjectEntry[]. After some searching I found that I needed to add the following code:

Code: Select all

protected override void OnMdiChildActivate(EventArgs e)
                  BindingFlags.Instance | BindingFlags.SetProperty |
                  BindingFlags.NonPublic, null,
                  this, new object[] { null });
            catch (Exception)
                // Something went wrong. Maybe we don't have enough permissions 
                // to perform this or the "FormerlyActiveMdiChild" property 
                // no longer exists. 
Now when I run the program and open and close the child form and take a snapshot, I see a control called ToolStripScrollButton that has been GC's but not properly disposed.

It looks like the child form is no longer in memory.

Do I need to do some type of cleanup (maybe in the form.closing event) to fix the ToolStripScrollButton issue?

Posted: Mon Dec 14, 2009 4:29 pm
by Andreas Suurkuusk
Having just a few undisposed ToolStripScrollButton instances will probably not noticably affect the performance or memory usage of the application. Additionally, it's not always possible to make sure that instances created by the framework are correctly disposed. Still, it's good to try to dispose as many instances as possible and maybe it is possible to dispose the ToolStripScrollButton instance as well. What does the allocation call stack of the instance look like?

Posted: Mon Dec 14, 2009 4:38 pm
Is there a way for me to upload the session info, I think that would be the easiest way.

Posted: Mon Dec 14, 2009 7:14 pm
by Andreas Suurkuusk
Yes, you can upload it to our support-FTP. Please contact us at and I will provide you with the login information.

Re: ContextMenuStrip issue

Posted: Mon Feb 22, 2010 4:21 pm
Here is the call stack:

System.Windows.Forms!System.Windows.Forms.ToolStrip.OnLayout( LayoutEventArgs )
System.Windows.Forms!System.Windows.Forms.ToolStripDropDown.OnLayout( LayoutEventArgs )
System.Windows.Forms!System.Windows.Forms.ToolStripDropDownMenu.OnLayout( LayoutEventArgs )
System.Windows.Forms!System.Windows.Forms.Control.PerformLayout( LayoutEventArgs )
System.Windows.Forms!System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.PerformLayout( IArrangedElement,string )
System.Windows.Forms!System.Windows.Forms.Layout.LayoutTransaction.DoLayout( IArrangedElement,IArrangedElement,string )
System.Windows.Forms!System.Windows.Forms.Control.OnFontChanged( EventArgs )
System.Windows.Forms!System.Windows.Forms.ToolStrip.OnFontChanged( EventArgs )
System.Windows.Forms!System.Windows.Forms.ToolStripDropDownMenu.OnFontChanged( EventArgs )
System.Windows.Forms!System.Windows.Forms.Control.set_Font( Font )
System.Windows.Forms!System.Windows.Forms.ToolStrip.set_Font( Font )
System.Windows.Forms!System.Windows.Forms.ToolStripDropDown.set_Font( Font )
HRIChimp.Win.SubjectInfo!HRIChimp.Win.SubjectInfo.SubjectInfo.InitializeComponent() SubjectInfo.Designer.cs
HRIChimp.Win.SubjectInfo!HRIChimp.Win.SubjectInfo.SubjectInfo..ctor( int,int,int,string ) SubjectInfo.Designer.cs
HRIChimp.Win.Search!HRIChimp.Win.Search.Search.grdSearch_DoubleClickRow( object,DoubleClickRowEventArgs ) Search.cs
Infragistics2.Win.UltraWinGrid.v5.3!Infragistics.Win.UltraWinGrid.UltraGrid.OnDoubleClickRow( DoubleClickRowEventArgs )
Infragistics2.Win.UltraWinGrid.v5.3!Infragistics.Win.UltraWinGrid.UltraGrid.FireEvent( GridEventIds,EventArgs )
Infragistics2.Win.UltraWinGrid.v5.3!Infragistics.Win.UltraWinGrid.GridCellEmbeddableEditorOwnerInfoBase.OnEditorDoubleClick( EmbeddableUIElementBase,EmbeddableClickEventArgs )
Infragistics2.Win.v5.3!Infragistics.Win.EmbeddableUIElementBase.RaiseDoubleClickEvent( UIElement,bool )
Infragistics2.Win.v5.3!Infragistics.Win.EmbeddableUIElementBase.OnDoubleClick( bool )
Infragistics2.Win.v5.3!Infragistics.Win.UIElement.OnDoubleClick( bool )
Infragistics2.Win.v5.3!Infragistics.Win.ControlUIElementBase.ProcessDoubleClick( object,EventArgs )
System.Windows.Forms!System.Windows.Forms.Control.OnDoubleClick( EventArgs )

Re: ContextMenuStrip issue

Posted: Tue Feb 23, 2010 9:42 pm
by Andreas Suurkuusk
The private ToolStripDropDownMenu.UpScrollButton property will create one instance of ToolStripScrollButton in its getter. This instance will never be disposed. The base class ToolStripControlHost adds quite a few event handlers to an internal Control, which are removed in Dispose. In similar cases failing to call Dispose could potentially cause a memory leak, but in the case of the UpScrollButton, the life-time of the internal control is the same as the lifetime of the ToolStripDropDownMenu instance. So, as long as the ToolStripDropDownMenu is correctly GCed, the missing Dispose call will probably not cause any problems (apart from slighty worse heap utilization).