If you have a singleton object like so: class foo { static foo SINGLE = new foo(); }
foo.SINGLE is a static reference that never goes away. Therefore, the object it points to is never garbage collected. YMMV, so write a simple test to prove it. Set a createdTime variable in the contructor and print it to stdout whenever the object is called. If the time changes, your object is different (though I don't expect it to be). You can do the same with your object's hashCode. -----Original Message----- From: Adolfo Miguelez [mailto:[EMAIL PROTECTED]] Sent: Friday, January 31, 2003 10:21 AM To: [EMAIL PROTECTED] Subject: RE: are static classes GC'd? I agree. But, could the hashtable be collected before since it has not references in the method? Or is TemplatesCache.getInstance().get("key"); considered as a reference? Thanks >From: "John Espey" <[EMAIL PROTECTED]> >Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]> >To: "Struts Users Mailing List" <[EMAIL PROTECTED]> >Subject: RE: are static classes GC'd? >Date: Fri, 31 Jan 2003 09:07:18 -0600 > >As long as the objects aren't wrapped in weak references, I don't see how >they would get garbage collected (they still have an active reference in >the >hashtable) > >-----Original Message----- >From: Adolfo Miguelez [mailto:[EMAIL PROTECTED]] >Sent: Friday, January 31, 2003 8:57 AM >To: [EMAIL PROTECTED] >Subject: RE: are static classes GC'd? > > > >Sorry, of course I meant the unique instance of the static class. > >We have a templates caches filled under demand, and implemented as a >singleton hashtable. We suspect that GC could be cleaning the cache. > >Under heavy stress we are getting some errors and we are looking for the >source. > >The invocations are in some methods: > >TemplatesCache.getInstance().put("key", object); > >or > >TemplatesCache.getInstance().get("key"); > >They have not any more references that the previous ones from the rest of >the code. Are they enough to avoid being GC'd? > >Adolfo. > > >From: "John Espey" <[EMAIL PROTECTED]> > >Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]> > >To: "Struts Users Mailing List" <[EMAIL PROTECTED]> > >Subject: RE: are static classes GC'd? > >Date: Fri, 31 Jan 2003 08:46:13 -0600 > > > >I believe classes are never garbage collected, only objects. What sort >of > >issue are you having where this question arose? > > > >-----Original Message----- > >From: Adolfo Miguelez [mailto:[EMAIL PROTECTED]] > >Sent: Friday, January 31, 2003 8:03 AM > >To: [EMAIL PROTECTED] > >Subject: are static classes GC'd? > > > > > >A core Java question. Can not find the solution so we would appreciate >any > >pointer or reference. > > > >Are static classes eligible for being Gc'd? How does behave GC with >static > >classes? > > > >TIA, > > > >Adolfo. > > > > > > > > > > > >_________________________________________________________________ > >The new MSN 8: advanced junk mail protection and 2 months FREE* > >http://join.msn.com/?page=features/junkmail > > > > > >--------------------------------------------------------------------- > >To unsubscribe, e-mail: [EMAIL PROTECTED] > >For additional commands, e-mail: [EMAIL PROTECTED] > > > > > >--------------------------------------------------------------------- > >To unsubscribe, e-mail: [EMAIL PROTECTED] > >For additional commands, e-mail: [EMAIL PROTECTED] > > >_________________________________________________________________ >STOP MORE SPAM with the new MSN 8 and get 2 months FREE* >http://join.msn.com/?page=features/junkmail > > >--------------------------------------------------------------------- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] > > >--------------------------------------------------------------------- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] _________________________________________________________________ Add photos to your messages with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]