Is there any downside of calling GC.SuppressFinalize(object)
multiple times?
Protected Dispose(bool)
method of the dispose pattern checks whether it is called before but there is no such check in the public Dispose()
method.
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (_Disposed)
return;
if (disposing)
{
// Cleanup managed resources.
}
// Cleanup unmanaged resources.
_Disposed = true;
}
~MyClass() { Dispose(false); }
Is it ok to call the Dispose()
method of a MyClass
instance multiple times?