tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject RE: Memory Usage and Garbage Collection
Date Fri, 03 Jan 2003 23:05:34 GMT

On Fri, 3 Jan 2003, Brandon Cruz wrote:

> Date: Fri, 3 Jan 2003 16:23:24 -0600
> From: Brandon Cruz <>
> Reply-To: Tomcat Users List <>,
> To: Tomcat Users List <>
> Subject: RE: Memory Usage and Garbage Collection
> Craig,
> >From what you have been saying...
> 1)For every single request to a servlet or JSP page, a new instance of that
> class is created?

NO!  It's exactly the opposite -- the same instance gets reused every

>  For example, if there is one JSP page and ten people
> access that one page over the course of a day, 10 separate instances of the
> same class are created and will never be gc'd until the webapp or tomcat is
> restarted?
> 2)If this is true, it looks to me like any java application in the world
> eventually has to be restarted as more and more people access it.  Buying
> more memory would prolong the time to restart the application, but
> eventually all the instances created will take up all the available RAM.  Is
> this correct?

The point I was trying to make is that code you *call* from your servlets
and JSPs can create memory leaks, and there's not necessarily anything
that you (as the author of the servlet or JSP) page can do about it.  You
can't even tell that it's happening unless you have access to the source
code of the classes you're calling.

Assume that you implement something like the "complex example" from my
previous mail, and every call to the getOtherObject() method specifies a
different id value.  The old OtherObject instances will *not* be GC'd,
because there are live references to them -- even if they are not in your
servlet, they still exist in the JVM.  And the fact that there is only one
instance of your servlet is not relevant to this memory leak, because it
is not your servlet instances that are being accumulated.

It is not good enough to just release references in your servlet when you
are through with an object.

> Brandon


To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message