Sam Heisz wrote:

> wes> What it may have meant was if Object A is only referred to by
> Object B
> wes> and Object B is only referred to by Object A, they can be garbage
> wes> collected -- I can see where simple implementations of a garbage
> wes> collector wouldn't be able to deal with the circular references.
>
> It seems that a case of circularity like this would be more difficult
> for the gc to detect; the gc would have to determine the circularity of
> the references _before_ it could garbage collect. With a given object A
> as a candidate for garbage collection, instead of simply scanning its
> list of all variables which point to an object for a reference to A, it
> would have to look at each item in the list and follow it through before
> it determined if it was circular or not.
>

It's not actually that hard to detect, but a GC implementation that uses marking
probably doesn't care -- it simply walks the entire object tree (well, technically
it's probably a "forest" rather than a "tree" but you get the idea), marking all
objects that are referenced from other objects.  Any object not so marked is either
an orphan, pointed at by an object not currently live, or part of a circularity
chain.  In any event, it's subject to collection.

Of course, the real algorithms used in JVMs are qutie a bit more sophisticated, but
the same principle applies:  if there are no valid references from live objects,
then the candidate object can be GC'd safely.

>
> Sam

Craig McClanahan

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to