How to reduce the memory used by Tomcat?
Solution 1:
The issue here isn't really tomcat, it's java generally. There are a number of different places where java uses memory. The java runtime uses it's own memory and that's going to be included in your number, additionally, java breaks memory down into four distinct locations:
The Heap: This is the memory used to store your objects and is controlled by the
-Xms
and-Xmx
parameters.The Stack: This is the memory used to store the stack frames for the threads that your program maintains and can be controlled with the
-Xss
parameter.Permgen Memory: This is the memory used to store your compiled classes and pooled strings as well as some other things and can usually be controlled with
-XX:MaxPermSize
although the-XX
represents a debugging parameter, so there's no guarantee it's on all JVM's. But, the default Sun/Oracle reference implementations have always had them.JNI Allocated Memory Any classes utilizing native methods and JNI could potentially allocate unlimited memory. This memory comes from the OS and not the heap and there's no way of knowing how much memory a native class will use without having access to the source.
An overview of the java memory model is probably beyond the scope of the answer to this question and I couldn't find a good concise article/description on the internet, but the short answer to your question is if you are trying to limit the absolute amount of memory used by a java program, there is no easy way to do it. Heuristically, probably cut your -Xms
and -Xmx
parameters to 128m and you should get close, but it's really going to depend on your application.