The finalizer is the latest attempt to verify that something is cleaned up correctly and is usually reserved for objects that wrap unmanaged resources , such as unmanaged descriptors, etc. that will not collect garbage.
Itβs rare to write a finalizer. Fortunately (and unlike IDisposable ), finalizers do not need to be propagated; so if you have a ClassA with a finalizer and a ClassB that wraps ClassA , then ClassB does not need a finalizer, but it is likely that ClassA and ClassB will implement IDisposable .
For managed code, usually IDisposable . Even if you do not clean it correctly, ultimately managed objects will be collected (provided that they are released).
Marc gravell
source share