Form Dispose Very Slow RRS feed

  • Question

  • Hi,


    A particular form in our application is taking 5-10 seconds to close.  There is no custom code executing when the form is closed and I've isolated the problem to the following line in the dispose method:

    base.Dispose( disposing );


    Using the Windows performance tool it looks as though it's the garbage collector which is taking the time.  Is there anything else I can use to verify this or help find the root cause of the problem?


    Thanks for your help.



    Wednesday, April 30, 2008 12:36 PM

All replies

  • The garbage collector is not involved while Control.Dispose() is executing.  It is resetting data bindings, calling DestroyWindow() to release window handles, releasing ActiveX controls, that sort of thing.  You'll have to tell us more about what kind of controls are used by the form.  Or start removing controls to see which one is the laggard.
    Wednesday, April 30, 2008 12:59 PM

    The form is a grid of charts, 50 Ax controls in total.  Profling the code including .NET methods I see the following:


    UnsafeNativeMethods.WaitMessage() - called 174 times, takes 5.66 seconds.

    Control.DisposeAxControls() - called 810 times, takes 2.1 seconds.

    GC.Collect() - called 50 times, takes 2.03 seconds.


    I'd accept disposing a form with a lot of Ax controls to take a bit longer but not the amount I'm seeing.  It's also odd DisposeAxControls is called over 800 times.



    Wednesday, April 30, 2008 1:55 PM