It feels like you're still embarrassed even though you accepted the answer. Let me explain:
The garbage collector (GC) has the unenviable task of removing any objects from memory that are inaccessible.
reachability
Object A is accessible only when there is any chain of links from any GC-root to the object. Examples of roots are the stack and any static fields. Thus, to determine if A reachable, all that the GC requires is to find a link on the stack that references an object that has a reference related to an object ... that refers to object A If he cannot find such a chain, object A inaccessible. one
So, once the GC determines that A unavailable, it will want to remove it from memory. However, before he does, GC will check if A finalizer ( ~A ) that needs to be started. If not, it removes A from memory, and GC executes with it.
Completion
However, if A has a finalizer to be launched, it cannot delete the object from memory until the finalizer completes. Thus, it adds a reference to A in the finalizer queue and does not delete the object from memory (for now). The garbage collector now works with A However, when the GC starts up again, it will again try to determine if A is available. Fortunately, the finalizer queue is also one of the roots of the garbage collector, so it determines that there is a link from the finalizer queue to A , so A reachable and will not be deleted from memory again.
Next comes the finalizer thread, a thread that periodically checks to see if there are any objects in the finalizer queue. If there is, he chooses one and runs his finalizer method. In the end, the finalizer thread will run finalizer A Once this is done, the reference to A will be removed from the finalizer queue.
Cleaning
Then, after some time, the garbage collector starts up again and again tries to determine if A is available. Since it is currently not mentioned anywhere, not even from the finalizer queue, A not available. GC removes A from memory.
As you can see, usually the GC can delete inaccessible objects in the same collection cycle that it detects, but when the object has a finalizer to be launched, it can take several cycles for the collected object. Therefore, CA1063 recommends placing GC.SuppressFinalize() in the Dispose method so that the GC knows that objects do not need to be modified before they are deleted from memory. Thus, object 2 is always deleted from memory.
Note that when you don’t have a finalizer, you do not need to add GC.SuppressFinalize() , so the CA1063 warning is a little redundant in this regard.
More information on the garbage collector can be found in this MSDN article .
1 ) Reachability is the reason why links to null are usually set after they are removed. This makes the reference object the most likely unreachable, and therefore the candidate to be deleted.
2 ) . It is possible (but not recommended) to resurrect A using the finalizer to add a reference to A from another object with an achievement or root (for example, a static field). This allows A accessible again, and the garbage collector will not delete it. However, its finalizer will not start again, as it has already been called once.