Skip to content

Instantly share code, notes, and snippets.

@chrisnas
Last active June 30, 2021 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisnas/0d68aa1ca411c5b5f59f75ec1ea035d7 to your computer and use it in GitHub Desktop.
Save chrisnas/0d68aa1ca411c5b5f59f75ec1ea035d7 to your computer and use it in GitHub Desktop.
class DisposableMe : IDisposable
{
private bool _disposed = false;
// 1. field that implements IDisposable
// 2. field that stores "native resource" (ex: IntPtr)
~DisposableMe()
{
Cleanup("called from GC" != null);
} // = true
public void Dispose()
{
Cleanup("not from GC" == null);
} // = false
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment