I know that in C#, if you write ~MyClass()
, this basically translates to override System.Object.Finalize()
. So, whether you write the destructor or not, every type in CLR will have a Finalize()
method in it (of System.Object
at least).
1] So, does it mean that, every object, by default, has a finalizer ?
2] What is the basis for the CLR to decide that an object should be put through finalization queue ?
I'm asking this, because, I had a class, say ManagedResourceHolder
that implemented IDisposable
, but did not call GC.SuppressFinalize(this)
in its IDisposable.Dispose()
method. The class did not hold any unmanaged resources, and there was no need for the ~ManagedResourceHolder()
method, which in turn meant no need for the GC.SuppressFinalize(this)
call as there was no finalizer.
3] In context of the above scenario, is it always necessary to provide a finalizer when you implement IDisposable ? (even on a class that holds no unmanaged resources)
The FxCop rule CA1816 was giving me a violation on this and the response I got here when I asked in the CA forum on MSDN confused me.
Thanks.