views:

337

answers:

2

Hi,

I know there are several memory types that Tomcat uses when running.

The only I have ever used - java heap. It can be controlled through JAVA_OPTS env property with something like '-Xmx128M -Xms64M'

I have found that there is also -XX:MaxPermSize, -XX:MaxNewSize and etc.

The reason I'm asking is that I'm trying to launch Tomcat5.5 on 200Mb RAM memory (it is VPS server). I have setup java heap size with '-Xmx128M -Xms64M', but it seems that right from startup it consumes more than that (if ever can start. Sometimes startup fails right off the bat with OutOfMemoryException), with no applications have been deployed

Noticable thing is that if I launch maven's tomcat plugin, it works just fine. Only separate tomcat fails with memory.

Thanks in advance for your ideas.

+2  A: 

As you say, heap memory is just one of the JVM's memory pools, there are others.

Read this to get an idea of what they are, how to control them, and how to monitor them:

http://java.sun.com/j2se/1.5.0/docs/guide/management/jconsole.html

Heap and Non-heap Memory

The JVM manages two kinds of memory: heap and non-heap memory, both created when it starts.

Heap memory is the runtime data area from which the JVM allocates memory for all class instances and arrays. The heap may be of a fixed or variable size. The garbage collector is an automatic memory management system that reclaims heap memory for objects.

Non-heap memory includes a method area shared among all threads and memory required for the internal processing or optimization for the JVM. It stores per-class structures such as a runtime constant pool, field and method data, and the code for methods and constructors. The method area is logically part of the heap but, depending on implementation, a JVM may not garbage collect or compact it. Like the heap, the method area may be of fixed or variable size. The memory for the method area does not need to be contiguous.

In addition to the method area, a JVM implementation may require memory for internal processing or optimization which also belongs to non-heap memory. For example, the JIT compiler requires memory for storing the native machine code translated from the JVM code for high performance.

skaffman
A: 

Read here for some tips on setting the java heap size. It is quite strange that Tomcat is giving you OutOfMemoryExceptions even without any applications deployed. Perhaps there is something wrong with your configuration (what OS are you using, how do you start Tomcat?).

kgiannakakis