Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Finalize</strong></p> <ul> <li>Finalizers should always be <code>protected</code>, not <code>public</code> or <code>private</code> so that the method cannot be called from the application's code directly and at the same time, it can make a call to the <code>base.Finalize</code> method</li> <li>Finalizers should release unmanaged resources only.</li> <li>The framework does not guarantee that a finalizer will execute at all on any given instance.</li> <li>Never allocate memory in finalizers or call virtual methods from finalizers.</li> <li>Avoid synchronization and raising unhandled exceptions in the finalizers.</li> <li>The execution order of finalizers is non-deterministic—in other words, you can't rely on another object still being available within your finalizer.</li> <li>Do not define finalizers on value types.</li> <li>Don't create empty destructors. In other words, you should never explicitly define a destructor unless your class needs to clean up unmanaged resources and if you do define one, it should do some work. If, later, you no longer need to clean up unmanaged resources in the destructor, remove it altogether.</li> </ul> <p><strong>Dispose</strong></p> <ul> <li>Implement <code>IDisposable</code> on every type that has a finalizer</li> <li>Ensure that an object is made unusable after making a call to the <code>Dispose</code> method. In other words, avoid using an object after the <code>Dispose</code> method has been called on it.</li> <li>Call <code>Dispose</code> on all <code>IDisposable</code> types once you are done with them</li> <li>Allow <code>Dispose</code> to be called multiple times without raising errors.</li> <li>Suppress later calls to the finalizer from within the <code>Dispose</code> method using the <code>GC.SuppressFinalize</code> method</li> <li>Avoid creating disposable value types</li> <li>Avoid throwing exceptions from within <code>Dispose</code> methods</li> </ul> <p>Dispose/Finalized Pattern</p> <ul> <li>Microsoft recommends that you implement both <code>Dispose</code> and <code>Finalize</code> when working with unmanaged resources. The <code>Finalize</code> implementation would run and the resources would still be released when the object is garbage collected even if a developer neglected to call the <code>Dispose</code> method explicitly.</li> <li>Cleanup the unmanaged resources in the <code>Finalize</code> method as well as <code>Dispose</code> method. Additionally call the <code>Dispose</code> method for any .NET objects that you have as components inside that class(having unmanaged resources as their member) from the <code>Dispose</code> method.</li> </ul>
 

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