Could not allocate enough heap space to Java

Eric Taix picture Eric Taix · Apr 26, 2011 · Viewed 21.1k times · Source

We have an application which was running fine for one year. It is a web application, running under Tomcat 5.5 + JDK 1.5 under Microsoft Cluster on Windows Server 2003 Enterprise Edition Service Pack 2. The server has 11Gb of RAM (I know that it is useless!) with the following description "Physical Address Extension": I don't know what that means.

The Tomcat service is configured with the following parameters: -Xmx1024m -Xms128m

Since last week, the service doesn't want to start anymore and stops with the following error message: "Could not allocate enough heap space".

We tried several tests:

  • java -Xmx1024m -version => Failed
  • java -Xmx758m -version => Failed
  • java -Xmx512m -version => Passed

So we can use less memory for the maximum heap size, but it is not an acceptable workaround because the number of users will increase in few months and we need to set the maximum heap size to 1024Mb.

Also I don't understand why it worked fine and then suddenly it stopped working! It seems that the OS is now unable to allocate contiguous memory, or something else (page file size, user memory allocation, ...)

It's quite difficult to know if something changed (OS patch, configuration, ...) because the web application is running on the customer server and we don't have access to it.

Answer

Peter Lawrey picture Peter Lawrey · Apr 26, 2011

Java requires continous memory. On 32-bit OSes this limits you to between 1.2 and 1.4 GB on Windows. However if your memory is fragmented due to other programs which are running, you might get a much smaller region of memory.

You won't get this problem with a 64-bit OS and you can even allocate far more memory to the jVM as well (if you use a 64-bit JVM)