继承IDisposable接口 释放分配的非托管资源 public void Dispose() { Dispose(true); GC.SuppressFinalize(true); // as a service to those who might inherit from us } /// <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 ----------------其它处理 }
dispose不用管了?是不是呢?那可就太简单了。
怎么 dispose?
要继承:IDisposable 接口 或 继承一个 几经有 dispose 的类才行
释放分配的非托管资源
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(true); // as a service to those who might inherit from us
} /// <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
----------------其它处理
}