标签:end 接口实现 收集 nal ptr ble style this ram
public class MyClass : IDisposable { #region 变量声明 // 指向外部非托管资源 private IntPtr handle; // 此类使用的其它托管资源. private Component Components; // 跟踪是否调用.Dispose方法,标识位,控制垃圾收集器的行为 private bool isDisposed = false; #endregion #region Finalizer ~MyClass() { Dispose(false); } #endregion #region IDispseable 接口实现 public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } #endregion #region 释放方法 /// <summary> /// 释放非托管资源 /// </summary> /// <param name="isManual">手动调用为true,系统调用为flase</param> protected virtual void Dispose(bool isManual) { if (isDisposed) return; isDisposed = true; //释放非托管资源 handle = IntPtr.Zero; if (isManual) { //释放其他disose对象 Components?.Dispose(); } } #endregion }
标签:end 接口实现 收集 nal ptr ble style this ram
原文地址:https://www.cnblogs.com/nocanstillbb/p/10298393.html