-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Torsten,

On 2/19/2010 10:13 AM, Torsten wrote:
> I have a HTTPServlet that takes up a lot of memory. The servlet is
> initialized when its web page is opened for the first time. Then,
> memory consumption of the tomcat process rises by up to 400MB. This
> amount of memory is never released again, then, even though the
> servlet's web page is not accessed anymore and there is no activity
> in the servlet anymore.

I believe initialized servlets aren't taken out of service until Tomcat
undeploys the webapp, so it's not surprising that the servlet "stays" in
memory.

> I wonder what I can do to make Tomcat unload my servlet after usage
> automatically. I read in the specs that the decision when a servlet
> is being unloaded by calling its destroy() method is up to the
> servlet container. However, it does not seem to unload a servlet at
> all, even though the complete process becomes very slow and all other
> servlets running inside the container are affected.

Sounds like you have a resource (memory) leak.

Try this:

1. Stop Tomcat, then re-start it.
2. Use a memory profiling tool such as "jmap -histo <pid>" to get a heap
object histogram and save it to a file (there are more sophisticated
tools that can help, here, but jmap might just pay off with little work)
3. Hit the servlet that eats-up all the memory
4. Repeat step #2
5. Compare the two heap object histograms to see if there are a whole
lot of new instances of something specific (like cached database
objects, parsed XML data, whatever)

You might get lucky and see that thousands of instances of some class
have been allocated and are still in memory. From there, you may be able
to track down what is creating them.

There are two possibilities that come to mind immediately to me:

1. Poorly-written code that inadvertently retains references to a whole
lot of data
2. Code that caches a lot of data, where the cache needs to be tuned to
avoid caching so much data

It's odd that this memory allocation is "affecting" the other servlets,
though. Affecting them in what way? Making them slower?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkt+sAMACgkQ9CaO5/Lv0PDOOQCfbj8JzmA6diQ8Cn/cjPnx44ja
29sAn3DCV+h1LNoWaTOnZxyQ0vN/hmYP
=9GOK
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to