On 5/3/06, Peter Crowther <[EMAIL PROTECTED]> wrote:
> From: Leon Rosenberg [mailto:[EMAIL PROTECTED]
> Could you explain it a bit more? What's the difference whether I have
> 10 instances of the same class or just one for reloading?

In a Singleton:

- the class holds a reference to the classloader;

- the class holds a reference to the singleton instance;

- the instance holds a reference to the class.

My understanding is that classes cannot be GCed unless they have no
instances, and classloaders are (obviously) not collected until they
have no references from classes.  So singletons leave classes lying
around in your JVM.  More annoyingly, classes always occupy PermGen
space, so this junk class is now eating up precious space in PermGen -
hence the possibility of an OOME if you reload your webapp too many
times.  The solution is to implement appropriate listeners to make sure
the instance is not referenced by the class before the webapp is
unloaded.

That's a quick recap from memory.  I thoroughly expect Chuck to jump
into the conversation and point out where I've misinterpreted :-).

Ok, what you mean is, that the "instance" variable of the singleton is
static, and therefore can't be collected, because the class references
the object and the object references the class. I don't think that the
classloader plays a role here. Shouldn't the gc be able to resolve
cyclic references?
Even if it doesn't, is this a real problem? I mean reloading a webapp
in production environment is a greater nogo than using a singleton,
isn't it?

regards
Leon


                - Peter

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

Reply via email to