You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Øyvind Hvamstad <oy...@hvamstad.net> on 2003/01/02 17:02:35 UTC

Release of memory

Hi, I have a servlet that is generating reports on demand from a client
program. I'm using tomcat as servlet container, xml and xsl to generate
fo and fop to give me pdf. The reports tend to be big and memory is
being exhausted.

Can anyone tell me how to make tomcat release memory after a servlet is
finished? Now tomcat simply hold it and sooner or later my server starts
to swap processes because of it. It does so even if I force GC at the
end of the servlet. If it is left idle, it frees some over time, but it
takes to long.

Please help!

Øyvind Hvamstad


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Release of memory

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Fri, 3 Jan 2003, Øyvind Hvamstad wrote:

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

Because the theory of a servlet container is that you're going to get
*lots* of calls to your servlet, so why should the container waste the
time to init and destroy it on every single call?  For maximum
performance, you want it to be loaded and initialized once, and then just
the service() method called for every request.

Tomcat will call the destroy() method when you take the application out of
service -- either because you remove it or because you're shutting the
server down.

If you are calculating something that takes a lot of memory, and it
happens on every request, you should store the reference to that object in
a local variable inside the service() method instead of initializing it in
init().  This will also likely avoid thread safety problems when you start
getting more than one request at a time (there's only one copy of instance
variables in a servlet, because there is only one instance of the servlet
class being loaded).

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Release of memory

Posted by Øyvind Hvamstad <oy...@hvamstad.net>.
> -----Original Message-----
> From: news [mailto:news@main.gmane.org] On Behalf Of Bill Barker


> If you search
http://nagoya.apache.org/bugzilla/buglist.cgi?product=fop
> you
> will find several reports of memory leaks using fop.  Your best bet is
to
> take it up on the fop-users list.

I did. I got no answer. 
I found it out though. The current design of fop is not memory usage
transparent, and if you use one page-sequence in the document, the hole
thing is held in memory till the end.

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?


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Release of memory

Posted by Bill Barker <wb...@wilshire.com>.
If you search http://nagoya.apache.org/bugzilla/buglist.cgi?product=fop you
will find several reports of memory leaks using fop.  Your best bet is to
take it up on the fop-users list.

"�yvind Hvamstad" <oy...@hvamstad.net> wrote in message
news:000601c2b278$5dcb2810$24d2d5c1@templar...
Hi, I have a servlet that is generating reports on demand from a client
program. I'm using tomcat as servlet container, xml and xsl to generate
fo and fop to give me pdf. The reports tend to be big and memory is
being exhausted.

Can anyone tell me how to make tomcat release memory after a servlet is
finished? Now tomcat simply hold it and sooner or later my server starts
to swap processes because of it. It does so even if I force GC at the
end of the servlet. If it is left idle, it frees some over time, but it
takes to long.

Please help!

�yvind Hvamstad





--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>