6 Miscellaneous Programming Features
These motives lead to the notion of a finalization queue, which is a list containing dead objects that you are interested in subjecting to further processing. You may request the garbage collector to place objects on these queues by registering them at any time during their lifetime. (Registration depends on the same notion of "pointing to but not making a reference to" that constitutes weak pointers. For finalization, it is crucial that this registration does not constitute a reference with respect to the garbage collector. Otherwise the garbage collector would consider the object still "alive" and would not attempt to recover it.)
The Unique Access Property (i.e., that the pointer to an object that registers it for finalization is the only extant pointer to it, not including pointers within the object that refer to it) guarantees that objects on finalization queues are not referred to anywhere else. Another property, the Principle of Containment, means that if A points to B in a simple tree fashion (without circularities), and both are registered and become dead at the same time, then A will be finalized first and B will be finalized only when A becomes dead and is no longer registered.
If an object is registered in several queues, the order in which the object will appear in the queues is not specified.
Generated with Harlequin WebMaker