A
Alex Clark
Hi MS & All others,
I've been investigating a memory leak in my application which is proving
particularly hard to fix, and I came across something very unusual.
I've determined that the leak is caused by a particular form that won't
"dispose". I'm using a program called ".NET Memory Profiler" to check to
see whether there's still an instance of my form even after it has been
closed & disposed.
After doing some testing, I've now come across a very unusual situation: In
a simple little app, I can load Form2 from within Form1, display it using
ShowDialog, close it (and then call Dispose on it from within Form1) and the
memory profiler reports that there are 0 instances of Form2 currently
running, just as it should be.
However, if I have a context menu on Form2 and I display it (handling
Form2's click event and showing the menu from code), and then close &
dispose it, it remains in the list of instantiated classes. I have tried
this several times, and was able to end up with a list of over a dozen
instances of Form2 despite the fact they had been closed and disposed of.
This ONLY ever happened if I'd clicked to show the Context-Menu, if I didn't
do that then Form2 would happily Dispose.
Is there some quirk where extra code is needed to dispose of a Form after a
Context Menu has been shown? I tested this with a MainMenu instead and it
Disposed just fine. Could this be a memory leak in the Framework? I'll be
happy to post a sample project demonstrating it, but in order to see the
problem you will require some sort of profiling tool capable of examining
the Heap. I'm using VS.NET 2003, Framework 1.1, WinXP Pro.
Many thanks,
Alex Clark
I've been investigating a memory leak in my application which is proving
particularly hard to fix, and I came across something very unusual.
I've determined that the leak is caused by a particular form that won't
"dispose". I'm using a program called ".NET Memory Profiler" to check to
see whether there's still an instance of my form even after it has been
closed & disposed.
After doing some testing, I've now come across a very unusual situation: In
a simple little app, I can load Form2 from within Form1, display it using
ShowDialog, close it (and then call Dispose on it from within Form1) and the
memory profiler reports that there are 0 instances of Form2 currently
running, just as it should be.
However, if I have a context menu on Form2 and I display it (handling
Form2's click event and showing the menu from code), and then close &
dispose it, it remains in the list of instantiated classes. I have tried
this several times, and was able to end up with a list of over a dozen
instances of Form2 despite the fact they had been closed and disposed of.
This ONLY ever happened if I'd clicked to show the Context-Menu, if I didn't
do that then Form2 would happily Dispose.
Is there some quirk where extra code is needed to dispose of a Form after a
Context Menu has been shown? I tested this with a MainMenu instead and it
Disposed just fine. Could this be a memory leak in the Framework? I'll be
happy to post a sample project demonstrating it, but in order to see the
problem you will require some sort of profiling tool capable of examining
the Heap. I'm using VS.NET 2003, Framework 1.1, WinXP Pro.
Many thanks,
Alex Clark