[gclist] Java Phantom references.

Pekka P. Pirinen pekka@harlequin.co.uk
Fri, 16 Mar 2001 13:58:40 GMT


> First is there a Java Manual other than the Sun Website new enough to
> discuss phantom references?

That's canonical.  I suppose there must be other JDK 1.2 manuals by
now.  There's a nice article on the technicalities of weak refs at
<http://developer.java.sun.com/developer/technicalArticles/ALT/RefObj/index.html>.
I wrote precise definitions of the Java weakness concepts for the MM
Reference, see
<http://www.xanalys.com/software_tools/mm/glossary/p.html#phantom.reference>.

> What are they supposed to be used for?

Cleanup after the finalize method (which might well be inherited) has
run.  Also, I think it's nice for doing finalization (in the generic
sense) without opening the door for resurrection: you just subclass
PhantomReference to hold the info you need for finalization.

> How do collectors handle them? My guess is when the object is toast the
> phantom reference is put on a queue.

That's pretty much given, since one has to implement the
ReferenceQueue anyway.
-- 
Pekka P. Pirinen
Harlequin Limited