Will undisposed modally shown forms cause memory leaks or not?

  • Thread starter Thread starter Gabriel Lozano-Morán
  • Start date Start date
G

Gabriel Lozano-Morán

I have created a small application that will open 1000 times a new form and
i have put in the load of the form DialogResult = DialogResult.OK. I do not
call the dispose each time. Using .NET memory profile I can see how the
number of undisposed instances increases. I need to know if this causes
memory leaks and if so how can I monitor memory leaks?

Gabriel Lozano-Morán
 
Gabriel Lozano-Morán said:
I have created a small application that will open 1000 times a new form and
i have put in the load of the form DialogResult = DialogResult.OK. I do not
call the dispose each time. Using .NET memory profile I can see how the
number of undisposed instances increases. I need to know if this causes
memory leaks and if so how can I monitor memory leaks?

Normally it doesn't cause memory leaks because the garbage collector will
finalize (and dispose) the form after some time. It's good practice to call
'Dispose' on forms shown by calling their 'ShowDialog' method.
 
Yes but the Finalizer will call the Dispose() method passing false. And the
destruction of the handle and window is done when true is passed to the
Dispose() method.

This should mean that the handle will not be destroyed nor the window? Or am
I missing something here? Because where exactly will Dispose(true) be called
by the GC?

Gabriel Lozano-Morán
 
Back
Top