Dispose的重写

public class test : IDisposable
{
        bool disposed = false;

        /// <summary>
        /// 回收对象
        /// </summary>
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (disposed)
                return;

            if (disposing)
            {
                if (Image != null)
                {
                    this.Image.Dispose();
                }
            }

            disposed = true;
        }
}


你可能感兴趣的:(回收,重写Dispose)