I am fighting exhausted resources in a large application with many
forms. It manifests itself by EVENTUALLY not being able to load an
ImageList. In researching this I see advice in previous postings to call
Dispose on a form when finished with the object, after a ShowDialog. It
is suggested this is necessary to avoid GDI resource leaks.

My question is, what about when you open the form non-modally with Show?
Will the form do its own Dispose, or am I obligated to find a way for
this to happen? If so, can someone suggest a strategy for managing this?

- Lee

Re: GDI resource leaks: Calling Dispose after ShowDialog by Armin

Armin
Wed May 18 12:30:11 CDT 2005

"Lee Gillie" <Lee@nospam.odp.com> schrieb
>I am fighting exhausted resources in a large application with many forms.
>It manifests itself by EVENTUALLY not being able to load an
> ImageList. In researching this I see advice in previous postings to
> call Dispose on a form when finished with the object, after a ShowDialog.
> It is suggested this is necessary to avoid GDI resource leaks.
>
> My question is, what about when you open the form non-modally with
> Show? Will the form do its own Dispose, or am I obligated to find a
> way for this to happen? If so, can someone suggest a strategy for
> managing this?

A non-modally show form is always automatically disposed when it's closed.


You might check out the CLR profiler:
http://msdn.microsoft.com/netframework/downloads/tools/default.aspx


How to use:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/scalenethowto13.asp


Armin


Re: GDI resource leaks: Calling Dispose after ShowDialog by Bruce

Bruce
Wed May 18 15:17:07 CDT 2005

Other things to look for:

Are Image objects (Bitmap objects, etc) being Dispose()d?

Are there any static events? If you subscribe to a static event then
the event will always have a reference to your event handler and you
will never be garbage collected.