[gclist] Finalization and death notices

Charles Fiterman cef@geodesic.com
Tue, 09 Oct 2001 12:05:51 -0500

At 05:13 PM 10/9/01 +0100, you wrote:
>It seems to me that finalization and death notices are trivially
>equivalent in power (in the sense that either can be readily
>implemented on top of the other).  If I'm wrong it's because I'm just
>guessing the semantics of death notices.  Can you tell me the real
>semantics of death notices?

Near death notices can do anything finalization can do but are stronger and
safer. They are stronger because the user controls the context of their
use. Thus near death notices can throw exceptions, use locks in a
coordinated way, use thread local storage etc. Also the user can traverse
unset near death notices. They are safer because the collector is never
told to run user code. I suppose the user could use a finalizer to create a
near death notice matching the stregnth but the safty issue would remain.

The semantics of a near death notice is the user goes to the collector with
a structure having the address of a double linked list and a weak reference
to an object. When the object is near death the weak reference becomes a
strong reference and the structure is unlinked from the double linked list
its on and linked to its designated list. The user is responsible for
dealing with the list as he will.

Death notices are more efficient than near death notices and weaker. They
behave like a near death notice except the weak reference is zeroed not
turned into a strong reference and the object is actually blown away. Thus
storage is cleared faster.