Created
October 26, 2017 17:39
-
-
Save inoto/304edf2db368d8d5fb5722792b767ee7 to your computer and use it in GitHub Desktop.
Dispose pattern
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
class Foo : IDisposable | |
{ | |
private bool _disposed; | |
~Foo() | |
{ | |
Dispose(false); | |
} | |
public void Dispose() | |
{ | |
Dispose(true); | |
GC.SuppressFinalize(this); | |
} | |
protected virtual void Dispose(bool disposing) | |
{ | |
if (!_disposed) | |
{ | |
if (disposing) | |
{ | |
// Free managed objects | |
} | |
// Free unmanaged objects | |
_disposed = true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment