[gclist] Weak References in Java
Alexandre Petit-Bianco
apbianco@cygnus.com
Tue, 22 Sep 1998 17:16:59 -0700
> As I understand it, Sun's JDK 1.2 has four different kinds of weak
> pointers, the difference among them being how they interact with
> finalization.
Not exactly. Objects referred to by Soft references might be reclaimed
by the GC whenever it feels like doing it, but there is some
computation involved before actually reclaiming an object:
http://www.javasoft.com/docs/books/tutorial/refobjs/about/soft.html:
The garbage collector might or might not reclaim a softly reachable
object depending on how recently the object was created or accessed,
but is required to clear all soft references before throwing an
OutOfMemoryError.
Objects referred to by Weak references will always be reclaimed by the
GC when it comes to consider them:
http://www.javasoft.com/docs/books/tutorial/refobjs/about/weak.html:
The only real difference between a soft reference and a weak
reference is that the garbage collector uses algorithms to decide
whether or not to reclaim a softly reachable object, but always
reclaims a weakly reachable object.
There is plenty of documentation on the subject at
http://www.javasoft.com/docs/books/tutorial/refobjs/
-- Alex (www.cygnus.com/~apbianco, apbianco@cygnus.com)
GPL'ed native Java(TM) compiler? Check sourceware.cygnus.com/java