tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shapira, Yoav" <Yoav.Shap...@mpi.com>
Subject RE: Release of memory
Date Fri, 03 Jan 2003 14:03:18 GMT
Hi,

>However, what does tomcat do after the "service" method returns? The
>Servlet interface has a "destroy" method, is it used? Why doesn't
Tomcat
>release the servlet instance? Can anyone explain the reason?

The servlet container is free to destroy servlets and JSPs at will.
Tomcat does not currently do this.  Assuming you want your code to be
portable, it shouldn't be rely on whether the container unloads your
servlets or not.

In general, don't rely on destroy() methods in servlets to free memory.
Most of your servlet's object allocation (and de-allocation) should be
in the various service() methods.  The exception to this are things like
DB connections, JNDI entries, etc that you want to create once (e.g. in
the servlet's init() method) and hold for the servlet's lifetime.

If you create objects in the service method and don't refer to them
elsewhere, they'll eventually be GCed even though the servlet instance
itself isn't destroyed.

Yoav Shapira
Millennium ChemInformatics

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