Call SuppressFinalize multiple times

Is there a drawback to calling GC.SuppressFinalize(object) multiple times?
The protected Dispose(bool) method of the deletion template checks to see if it has been 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); } 

Can I call the Dispose() method of an instance of MyClass several times?

+4
source share
1 answer

According to the docs: http://msdn.microsoft.com/en-us/library/system.gc.suppressfinalize.aspx , it sets a bit in the object header, so there should be no consequences for calling it once.

+5
source

Source: https://habr.com/ru/post/1434348/


All Articles