Skip to content

Instantly share code, notes, and snippets.

@inoto
Created October 26, 2017 17:39
Show Gist options
  • Save inoto/304edf2db368d8d5fb5722792b767ee7 to your computer and use it in GitHub Desktop.
Save inoto/304edf2db368d8d5fb5722792b767ee7 to your computer and use it in GitHub Desktop.
Dispose pattern
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