ContextMenuStrip issue

Use this forum for questions on how to use .NET Memory Profiler and how to analyse memory usage.

Moderator: SciTech Software

ContextMenuStrip issue

Postby tkelley@hrimaging.com » 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)
        {
            base.OnMdiChildActivate(e);
            try
            {
                typeof(Form).InvokeMember("FormerlyActiveMdiChild",
                  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?
T Kelley
tkelley@hrimaging.com
 
Posts: 7
Joined: Mon Dec 07, 2009 7:34 pm
Location: USA

Postby Andreas Suurkuusk » Mon Dec 14, 2009 4:29 pm

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?
Best regards,

Andreas Suurkuusk
SciTech Software AB
Andreas Suurkuusk
 
Posts: 981
Joined: Wed Mar 02, 2005 7:53 pm
Location: Sweden

Postby tkelley@hrimaging.com » 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.
T Kelley
tkelley@hrimaging.com
 
Posts: 7
Joined: Mon Dec 07, 2009 7:34 pm
Location: USA

Postby Andreas Suurkuusk » Mon Dec 14, 2009 7:14 pm

Yes, you can upload it to our support-FTP. Please contact us at support@scitech.se and I will provide you with the login information.
Best regards,

Andreas Suurkuusk
SciTech Software AB
Andreas Suurkuusk
 
Posts: 981
Joined: Wed Mar 02, 2005 7:53 pm
Location: Sweden

Re: ContextMenuStrip issue

Postby tkelley@hrimaging.com » Mon Feb 22, 2010 4:21 pm

Here is the call stack:

System.Windows.Forms!System.Windows.Forms.ToolStripDropDownMenu.get_UpScrollButton()
System.Windows.Forms!System.Windows.Forms.ToolStripDropDownMenu.SetDisplayedItems()
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 )
[Truncated]
T Kelley
tkelley@hrimaging.com
 
Posts: 7
Joined: Mon Dec 07, 2009 7:34 pm
Location: USA

Re: ContextMenuStrip issue

Postby Andreas Suurkuusk » Tue Feb 23, 2010 9:42 pm

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).
Best regards,

Andreas Suurkuusk
SciTech Software AB
Andreas Suurkuusk
 
Posts: 981
Joined: Wed Mar 02, 2005 7:53 pm
Location: Sweden


Return to Using .NET Memory Profiler

Who is online

Users browsing this forum: No registered users and 3 guests

SciTech Software logo

© Copyright 2001-2016. SciTech Software AB
All rights reserved.


SciTech Software AB
Kartvägen 21
SE-175 46 Järfälla
Sweden


E-mail: mail@scitech.se

Telephone: +46-706868081

cron