Showing posts with label OOME. Show all posts
Showing posts with label OOME. Show all posts

Friday, September 4, 2026

Java/Tomcat: Understanding Out of Memory Error (OOME)

Out of Memory Error (OOME) in Tomcat

What is an Out of Memory Error, and why does it happen?

The basic cause of an OutOfMemoryError (OOME) is that the JVM cannot allocate enough memory for an application to continue running. In a Tomcat environment, this can result in an application failure or, depending on the situation, the Tomcat process being unable to continue.

The error itself is not particularly difficult to understand. The difficult part is finding the actual root cause.

A stack trace may show where the JVM ran out of memory, but it does not always identify why the application consumed so much memory. In many cases, the problem is related to the web application running inside Tomcat rather than Tomcat itself.

The code causing the problem may also look perfectly normal. For example, an application might load a large amount of data into memory, retain objects longer than necessary, or create too many objects during processing. This makes it difficult to identify which part of the application is actually responsible for the problem.

Here are some common causes of an OutOfMemoryError:

  • The JVM heap size is too small for the application's workload.
  • The application loads a very large file or a large amount of data into memory.
  • The application creates a large number of objects or collections.
  • Objects are unintentionally retained for longer than necessary, causing memory usage to grow.
  • Excessive recursion can cause a StackOverflowError rather than a heap OutOfMemoryError, so this should be considered a separate problem.
  • Too many threads can cause memory-related problems, although this may also result in errors such as Unable to create new native thread.
  • Running out of file descriptors is a separate operating-system resource issue and is not itself an OutOfMemoryError.
  • In older Java applications, a large number of web applications or classloaders could contribute to PermGen exhaustion.

Finding the Root Cause

Increasing the JVM heap size can sometimes reduce or temporarily resolve an OutOfMemoryError, but it does not necessarily fix the underlying problem. If the application continues to consume memory, increasing -Xmx only delays the failure.

For this reason, it is important to investigate the application's memory usage using appropriate JVM monitoring or profiling tools and identify which objects or parts of the application are consuming memory.

Note: PermGen applies to older Java versions. Java 8 removed PermGen and replaced it with Metaspace. Therefore, PermGen space errors are relevant mainly when troubleshooting older Java applications.