[gclist] Finalization and death notices
Nick Barnes
Nick.Barnes@pobox.com
Wed, 10 Oct 2001 16:10:19 +0100
At 2001-10-10 13:19:38+0000, kkonaka@softalia.com writes:
> hi!
>
> > 3) (near-death notice) The collector enqueues finalizable objects, and the
> > client decides when to run the finalizers. This is essentially the Java2
> > java.lang.ref.PhantomReference approach.
>
> really? what I have observed is PhantomReference gives back notices
> only _after_ the GC subsystem have already run the finalizers:
> http://www.geocrawler.com/archives/3/196/2001/5/100/5773756/
> so I was wondering if we can come up with some variant of
> PhantomReference which does inform user program _before_ finalizers
> are run - (still no definitive answer for this yet).
> I'm not at all sure if introduction of such Reference type
> (call it like EarlyPhasePhantomReference, or SlightlyStrongPhantomReference;
> whatever) would cause any catastrophic semantic trouble to java or not...
My mental notes on Java:
After there are no more direct references:
If there are SoftReferences, the object is retained until memory is
running low, then SoftReferences are cleared (before
OutOfMemoryError) and enqueued.
If there are WeakReferences but no SoftReferences, the
WeakReferences are cleared and enqueued.
If there are no SoftReferences or WeakReferences, the object is
finalized.
After the object has been finalized, PhantomReferences are cleared
and enqueued.
The WeakReference sounds like what you want, _but_ the WeakReference
may not be enqueued until after the finalizer runs. So I think the
only solution in Java is to redefine finalize() on the TargetClass, as
you mention in your advanced-java message.
Nick B