Dispose managed resources

  • Thread starter Thread starter gol
  • Start date Start date
G

gol

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
 
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

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.
 
Back
Top