Implement the IDisposable interface standard

December 3, 2010
The main purpose of this interface is to release unmanaged resources. When not using managed objects, the garbage collector automatically releases the memory allocated to the object. But can not predict when garbage collection
room. In addition, the garbage collector handle of the window or open the file and know nothing about unmanaged resources such as streams.
this interface, the Dispose method used in conjunction with the garbage collector explicitly release unmanaged resources. When no longer needed object, the object the user can call this method.
the following to achieve a standard IDisposable interface: public class MyClass: IDisposable {private bool _Disposed = false; public void Dispose () {Dispose (true); GC.SuppressFinalize (this);} ~ MyClass ( ) {Dispose (false);} private void Dispose (bool disposing) {if (! this._Disposed) {if (disposing) {/ / release resources} _Disposed = true;}}}

Posted: January 3rd, 2012
at 2:24pm by admin

Tagged with


Categories: Uncategorized

Comments: No comments