.netgarbage-collectionidisposablefinalizersuppressfinalize

Should I implement GC.SupressFinalize on IDisposable AND Finalize?


The code review checklist in my new client place has the following -

Class implementing Dispose and Finalize should have a call to GC.SupressFinalize in Dispose implementation

Why?

Should it not read as Class implementing IDisposable interface should have a call to GC.SupressFinalize in the Dispose implementation?

Or Am I missing something silly?


Solution

  • You're missing the fact that not every disposable class needs a finalizer - in fact, very few do, particularly due to .NET 2.0's SafeHandle type. If there's no finalizer, why would you need to call SuppressFinalize?