Achim,
> the "this.Dispose()" and "System.GC.Collect() methods are
> used in the closing event method. Some MB memory are left
Where is the closing event? Based on "this.Dispose" it is a method of the
form.
Is the call to GC.Collect in the closing event?
What about events after the closing event, such as the Closed event?
Think carefully about what you just said: In the closing event for the form
(where I have a reference to the form, hence everything that the form
references) I call this.Dispose, then I call GC.Collect. Why do I still have
memory occupied by this form?
Remember Dispose only releases unmanaged resources, it does nothing for
managed resources. Also for modeless forms Dispose is automatically called
in the Closed event, for modal forms you are responsible for calling
Dispose.
To get this to even half work, you would need to handle the Closed event for
your form in a different object, then be certain to clear the sender object
& any event handlers to ensure that nothing (that you are keeping) has a
reference to that form. Self references & Child controls can have a
reference to the form as they are going away also...
I'm saying half work, as I am sure the Forms library is doing something that
I am not aware of.
Using the Closed event is assuming that Closed is the absolute last event
that the form raises. I really do not know if it is or not. There is a
utility on Code Project that may be able to tell you.
http://www.codeproject.com/csharp/controlinspector.asp
Also you may want to follow GC.Collect with a call to
GC.WaitForPendingFinalizers, then a second call to GC.Collect &
GC.WaitForPendingFinalizers. Just be certain that you do not call GC.Collect
too often as you can actually hurt performance rather then help.
The following two articles covers when you should & should not call
GC.Collect.
http://msdn.microsoft.com/msdnmag/issues/1100/gci/
http://msdn.microsoft.com/msdnmag/issues/1200/GCI2/
Hope this helps
Jay
> Hi all,
> we're having developed a .NET Windows application in C#
[quoted text clipped - 8 lines]
> Best regards
> Achim