Hi,
When I create a Windows Form in VS 2005 I get the Dispose method created for
me in the Form.Designer.cs file. Some of the code that I get inside that
method takes care of cleaning up managed resources this way:

if (disposing && (components != null))
{
components.Dispose();
}

The question is whether this is enough to clean up all managed resources, or
I should add some code myself to clean up managed resources that I use.

Is System.Windows.Forms.Timer considered to be a managed resource? How is
this being cleaned up?

Thank you very much

Re: Dispose managed resources by Brian

Brian
Sun Sep 14 21:11:42 CDT 2008

On Sep 9, 12:46=A0am, gol <g...@discussions.microsoft.com> wrote:
> Hi,
> When I create a Windows Form in VS 2005 I get the Dispose method created =
for
> me in the Form.Designer.cs file. Some of the code that I get inside that
> method takes care of cleaning up managed resources this way:
>
> if (disposing && (components !=3D null))
> {
> components.Dispose();
>
> }
>
> The question is whether this is enough to clean up all managed resources,=
or
> I should add some code myself to clean up managed resources that I use.
>
> Is System.Windows.Forms.Timer considered to be a managed resource? How is
> this being cleaned up?
>
> Thank you very much

If your Form contains a reference to a object that implements
IDisposable then you should call Dispose on that object when the
Form's Dispose method is called.

Likewise, if your Form maintains an unmanaged resource then you need
to release that resource in the Form's Dispose method.

One thing to consider, however, is whether it makes more since to do
these in response to the Form closing.