Finalizing Your Code Properly
Classes with finalizers or destructors are more expensive to clean up than objects without destructors. This is because the garbage collector has to make two passes for objects with destructors: the first pass executes the destructor, and the second pass cleans up the object.
The garbage collector has two structures to manage objects with destructors: a finalization queue and a F-reachable queue. When an object with a destructor becomes unusable, a pointer to it is added to the finalization queue. This indicates that the object must have its destructor called before it's cleaned up. During a garbage collection, all entries in the finalization queue are moved to the F-reachable queue; their destructors are called; ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access