IDisposable Dispose

suggest change

.NET defines an interface for types that need a teardown method:

public interface IDisposable
{
  void Dispose();
}

Dispose releases resources. The garbage collector does not call Dispose. A database connection should be disposed by the owner so it returns to the pool, rather than waiting until the object is collected.

public void Dispose()
{
   if (null != this.CurrentDatabaseConnection)
   {
       this.CurrentDatabaseConnection.Dispose();
       this.CurrentDatabaseConnection = null;
   }
}

For an unmanaged pointer or a Win32 handle, derive a class from SafeHandle and use that type's release method.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents