Search code examples
winformsgarbage-collectiondisposemdi

Disposing MDI Child forms


According to the msdn

The two conditions when a form is not disposed on Close is when (1) it is part of a multiple-document interface (MDI) application, and the form is not visible; and (2) you have displayed the form using ShowDialog. In these cases, you will need to call Dispose manually to mark all of the form's controls for garbage collection.

How do I go about this for the first case? If I manually dispose, this.dispose() ,of the form and set a breakpoint within dispose (found in the form's designer file), the breakpoint is never reached.


Solution

  • Start by not hiding MDI child windows, there's little point. If you really do need to hide them then call their Dispose() method instead of their Close() method. Dispose() will also close the window if it isn't hidden.