难道Connection 对象是非托管的吗?
何时必须实现 IDisposable ,我一个DataAccess类用到了 SqlDataAdapter,是否一定要实现 IDisposable 接口,
以释放 SelectCommand.Connection 对象? 难道Connection 对象是非托管的吗?
我看到ms 的duwamish7.0 中是这么做的。
/// <summary>
/// Free the instance variables of this object.
/// </summary>
protected virtual void Dispose(bool disposing)
{
if (! disposing)
return; // we're being collected, so let the GC take care of this object
if (dsCommand != null )
{
if (dsCommand.SelectCommand != null)
{
if( dsCommand.SelectCommand.Connection != null)
dsCommand.SelectCommand.Connection.Dispose();
dsCommand.SelectCommand.Dispose();
}
dsCommand.Dispose();
dsCommand = null;
}
}