Skip to content

Instantly share code, notes, and snippets.

@dehghani-mehdi
Created March 6, 2024 05:37
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 dehghani-mehdi/38c30c739d3e8916064594abc5ede57d to your computer and use it in GitHub Desktop.
Save dehghani-mehdi/38c30c739d3e8916064594abc5ede57d to your computer and use it in GitHub Desktop.
IDisposable
// ref: https://stackoverflow.com/a/538238/3367974
public class Foo : IDisposable
{
protected void Dispose(Boolean disposing)
{
// free unmanaged resources
if (disposing)
{
// free managed resources
}
}
public void Dispose()
{
Dispose(true);
// prevent GC calling finalize later
GC.SuppressFinalize(this);
}
// add this if you have unmanaged resources
~Foo()
{
Dispose(false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment