Will undisposed modally shown forms cause memory leaks or not?

  • Thread starter Gabriel Lozano-Morán
  • 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
 
H

Herfried K. Wagner [MVP]

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.
 
G

Gabriel Lozano-Morán

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top