On Fri, 7 Apr 2000, Sam Heisz wrote:
sam>> What stops the instance from getting garbage collected? I read
that
sam>> starting version something-something-something, the garbage
collector
sam>> is more aggressive and will collect instances of objects that are
only
sam>> referred to by a member variable in the same class.

Wes Biggs wrote:
wes> Do you have a reference?  That would break tons of code out there,
wes> including parts of the JDK itself that utilize the singleton
pattern.

Java In Practise: Design Styles And Idioms For Effective Java
by Phil Bishop ,  Nigel Warren
ISBN 0201360659

page 131:

"JDK 1.1.x specification added the feature of class unloading...
where the only reference to the Singleton object is maintained within
the Singleton class itself, the garbage collector, in its enthusiasm to
dispose of any unused trash, may assume that the Singleton is
unreachable because no other object or class holds a current reference
to it and could quite legally garbage collect the object and unload the
class...'

It goes on to mention that you either have to maintain a reference to
the Singleton somewhere, or use the -noclassgc flag to disable class
unloading.

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.

Sam

===========================================================================
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