tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
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 <bcruz@norvax.com>
> Reply-To: Tomcat Users List <tomcat-user@jakarta.apache.org>,
>      bcruz@norvax.com
> To: Tomcat Users List <tomcat-user@jakarta.apache.org>
> 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
time.

>  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

Craig


--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message