Konrad L. M. Rudolph <ko************@madrat.net> wrote:
DC wrote: Is code like:
<code>
FormX f = new FormX();
f.ShowDialog();
f.Dispose();
GC.Collect();
</code>
bad thing or good thing?
it's useless I'd say. IMHO you only have to dispose of unmanaged
resources if you want to free memory. Disposing of a form which is not
in use anymore and out of scope is done automatically as soon as memory
is needed. f.Dispose() and GC.Collect() are therefore not needed unless
your form does some dirty things and overrides the Dispose() method of
the base class.
Windows handles are not an infinite resource, and not one which the
garbage collector keeps track of. While I agree that the call to
GC.Collect() isn't needed, you should *always* make sure that classes
which implement IDisposable have their Dispose methods called. There's
more to unmanaged resources than just memory!
I would, however, change the format of the code to:
using (FormX f = new FormX())
{
f.ShowDialog();
}
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too