Object not disposed after calling the Dispose() function.

Posted by Pavan Navali on Stack Overflow See other posts from Stack Overflow or by Pavan Navali
Published on 2010-05-07T05:58:39Z Indexed on 2010/05/07 6:08 UTC
Read the original article Hit count: 354

Filed under:
|

Hi,

I have query regarding the disposing of an object. The scenario is as follows.

In a Desktop Appication, developed in C#, I have a function in which a object in created like this.

namespace Class 1 { variables section; .... ....

Function1()
{
     local variables;
     try
     {
          Object1 obj = new Object1();
          ....
          ....
          if(true)
          {
              ....
          }
          else
          {
               **obj.Dispose();**
          }
      }
      catch()
      {}
      finally
      {}
 }

}

The object is not disposed when the else part is executed. The msdn link for this is

http://msdn.microsoft.com/en-us/library/system.componentmodel.component.dispose(VS.90).aspx

according to which the component should realase all the resources used by it.

I would like to know, why the object is not disposed.

Thank you.

Pavan Navali.

© Stack Overflow or respective owner

Related posts about c#

Related posts about dispose