File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Tomcat and the fly likes How Memory is used with Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "How Memory is used with Tomcat" Watch "How Memory is used with Tomcat" New topic

How Memory is used with Tomcat

Kim Kantola
Ranch Hand

Joined: May 17, 2001
Posts: 276
Hello All,
I am seeing some behaviour which does not seem to be correct, and I wanted to check to see if anyone could verify this. When I start my app using Tomcat 4.1, I can see Tomcat.exe in the Task Manager process screen that it is using about 47,000 K of memory. As I hit the app, visiting several pages, it goes up to about 90,000 k of memory. What seems strange to me, is that when I log out of my app, and close the browser, tomcat.exe is still listed at 90,000 k of memory. Shouldn't it go backdown to the startup value of 47,000 K since I closed down my app?
Thanks for any input,
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13036
Shouldn't it go backdown to the startup value of 47,000 K since I closed down my app?

No - why would you expect it to? Java does not trade memory back and forth with the operating system on a short term basis. That would be very slow and inefficient, especially in a web server.

By keeping the memory under the management of the JVM Tomcat will be able to handle the next request more quickly. You didn't "close down" your app, it is still resident.

If you want to look at memory use more closely use the Manager application display to see free and total memory.
Whoops - unearthing a Tomcat 4.1.30 version I see that the manager does NOT report memory use, thats an improvement in Tomcat 5. If you are stuck with Tomcat4 you can write your own servlet to show current memory usage using the Runtime freeMemory method.
[ December 21, 2005: Message edited by: William Brogden ]
Kim Kantola
Ranch Hand

Joined: May 17, 2001
Posts: 276
Wow, thank you so much for your speedy reply!
Still confused about one thing. After seeing the behavior documented above, I opened another browser and started hitting myapp again, and saw that the memory seemed to start growing again, using the 90k as a starting point. If the JVM had all that memory and no other browsers open, why wouldn't it use the 90k it had, and not go get more?
Forgive me if this is a stupid question, I am new to learning about memory!
PS, I am also trying deperatly to learn more about what is going on via the tomcat manager as you suggest. I have another posting here about that! Can't seem to see the info about threads and things that other people mention.
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Rather than try to pick up every discarded object as soon as it is freed, the JVM will wait until a certain percent of your allotted memory is used before running Garbage Collection (GC).

Garbage collection is an expensive operation and it makes sense for the JVM not to run it more than is absolutely necessary.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: How Memory is used with Tomcat
It's not a secret anymore!