suppressfinalize

When should I use GC.SuppressFinalize()?

匆匆过客 提交于 2019-11-26 06:51:20
问题 In .NET, under which circumstances should I use GC.SuppressFinalize() ? What advantage(s) does using this method give me? 回答1: SuppressFinalize should only be called by a class that has a finalizer. It's informing the Garbage Collector (GC) that this object was cleaned up fully. The recommended IDisposable pattern when you have a finalizer is: public class MyClass : IDisposable { private bool disposed = false; protected virtual void Dispose(bool disposing) { if (!disposed) { if (disposing) {