Calling
Dispose will not clean up the memory used by an object. Dispose
is meant to be used to run user defined code that releases resources
that are not automatically released - like file handles, network
handles, database connections etc.The likely culprit is probably the second form attaching events to objects that are outside it (perhaps the first form?) and never unattaching them. If you have any events in the second form, unattach them in your OnClose override - that will make the second form eligible for garbage collection. Note, .NET garbage collector is quite unpredictable and it might create a few instances of an object before cleaning up all the older instances that were eligible for collection. A way to know for sure (without resorting to memory profilers) is to put a breakpoint in the finalizer: public class MyForm : Form { GC.Collect(); MyForm finalizer. |
Wednesday, 22 August 2012
Dispose method
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment