We are developing a big .NET Windows Forms application. We are facing a memory leak/usage problem in that despite we are disposing the forms.
The scenario is like:
myform.showDialog
, show the details. The memory jumps from 60 KB to 105 MB.myform
to get back to grid, and dispose that form and set it to null. Memory remains at 105 MB.How can we free up the memory when we close myForm
?
We have already tried GC.Collect()
, etc., but without any result.
The first place to look for leaks is in event-handling rather than missing Dispose()
calls. Say your container (the parent form) loads a child form and adds a handler for an event of that child form (ChildForm.CloseMe
).
If the child form is intended to be cleared from memory then this event handler must be removed before it is a candidate for garbage collection.