[gclist] Finalization and death notices

Pekka P. Pirinen pekka.p.pirinen@globalgraphics.com
Wed, 10 Oct 2001 16:16:17 +0100


> > 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.
>
> what I have observed is PhantomReference gives back notices
> only _after_ the GC subsystem have already run the finalizers:

Well, yes, but you wouldn't usually use both.  I suspect Hans was
thinking of some scheme to implement near-death notices with them.

> I was wondering if we can come up with some variant of
> PhantomReference which does inform user program _before_ finalizers
> are run

Anyway, Java 2 has three Reference classes, all of which can be
enqueued - and the other two, SoftReference and WeakReference, are
handled _before_ the finalizers.  So you could probably use those.
See <http://www.memorymanagement.org/glossary/s.html#soft.reference>
and <http://www.memorymanagement.org/glossary/w.html#weak.reference>
for details.

In fact, I'm surprised you got anywhere with PhantomReference, since
get is always supposed to return null on it.  I think you're on the
wrong track here.

> I'm not at all sure if introduction of such Reference type
> would cause any catastrophic semantic trouble to java or not...

Introducing new Reference types would not be a problem, I could see a
system where the user could be allowed to.  But the language is
probably complicated enough already.
-- 
Pekka P. Pirinen
Real programs don't eat cache.