Created
January 18, 2013 22:49
-
-
Save petarvucetin/4569373 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DisposableClass : | |
IDisposable | |
{ | |
bool _disposed; | |
public void Dispose() | |
{ | |
Dispose(true); | |
GC.SuppressFinalize(this); | |
} | |
~DisposableClass() | |
{ | |
Dispose(false); | |
} | |
protected virtual void Dispose(bool disposing) | |
{ | |
if (_disposed) | |
return; | |
if (disposing) | |
{ | |
// free other managed objects that implement | |
// IDisposable only | |
} | |
// release any unmanaged objects | |
// set thick object references to null | |
_disposed = true; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IDisposable | |
{ | |
void Dispose(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SubDisposableClass : | |
DisposableClass | |
{ | |
private bool _disposed; | |
// a finalizer is not necessary, as it is inherited from | |
// the base class | |
protected override void Dispose(bool disposing) | |
{ | |
if (!_disposed) | |
{ | |
if (disposing) | |
{ | |
// free other managed objects that implement | |
// IDisposable only | |
} | |
// release any unmanaged objects | |
// set thick object references to null | |
_disposed = true; | |
} | |
base.Dispose(disposing); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment