On Wed, 25 Jul 2007 04:56:15 -0700, Jon Skeet [C# MVP] <sk***@pobox.com>
wrote:
Calling Dispose won't collect any memory. You could call GC.Collect
when you close the form, after making sure you no longer have any
references to the data. GC.Collect is generally not worth calling, but
when closing a form it may be reasonable.
Maybe. Though, I have to say...before I actually did any .NET
programming, I inferred all sorts of resource-management headaches caused
by garbage collection that would require calls to the GC.Collect() method,
all of which turned out to be non-issues once I started doing actual .NET
stuff.
When you have unmanaged stuff that has to be released at a specific point
in time, there's the Close() and/or Dispose() paradigm to take care of
that. For anything else, you really just don't care about something being
released. In neither case does GC.Collect() need to be called explicitly.
The one exception I can think of is after a form shown using ShowDialog()
has been closed or the form is an MDI form (both of these are mentioned
specifically in the docs for Form.Close()), and IMHO explicitly calling
Dispose() or using the "using" statement is better than calling the GC
directly. And of course this scenario doesn't relate directly to the
original post anyway, since they are not talking about unmanaged resources
(the managed List<will be automatically released at such time as the
memory is needed).
Pete