Note that there are some explanatory texts on larger screens.

plurals
  1. POWhen does CLR say that an object has a finalizer?
    text
    copied!<p>I know that in C#, if you write <code>~MyClass()</code>, this basically translates to <code>override System.Object.Finalize()</code>. So, whether you write the <em>destructor</em> or not, every type in CLR will have a <code>Finalize()</code> method in it (of <code>System.Object</code> at least).</p> <p>1] So, does it mean that, every object, by default, <strong>has</strong> a finalizer ?</p> <p>2] What is the basis for the CLR to decide that an object should be put through finalization queue ? </p> <p>I'm asking this, because, I had a class, say <code>ManagedResourceHolder</code> that implemented <code>IDisposable</code>, but did not call <code>GC.SuppressFinalize(this)</code> in its <code>IDisposable.Dispose()</code> method. The class did not hold any unmanaged resources, and there was no need for the <code>~ManagedResourceHolder()</code> method, which in turn meant no need for the <code>GC.SuppressFinalize(this)</code> call as there was no <em>finalizer</em>.</p> <p>3] In context of the above scenario, is it <strong>always</strong> necessary to provide a finalizer when you implement IDisposable ? (even on a class that holds no unmanaged resources)</p> <p>The FxCop rule <a href="http://msdn.microsoft.com/en-us/library/ms182269.aspx" rel="noreferrer">CA1816</a> was giving me a violation on this and the response I got <a href="http://social.msdn.microsoft.com/Forums/en-US/vstscode/thread/4e8a3155-6f12-4888-9ca1-f6762761e038" rel="noreferrer">here</a> when I asked in the CA forum on MSDN confused me.</p> <p>Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload