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.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents