Created
March 6, 2024 05:37
-
-
Save dehghani-mehdi/38c30c739d3e8916064594abc5ede57d to your computer and use it in GitHub Desktop.
IDisposable
This file contains hidden or 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
// 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