Sobes.tech
Senior

If an application has a heap of 3GB and a container of 3.1GB, and the application crashes without OOM in logs, why is that and how can it be fixed?

sobes.tech AI

Answer from AI

If the application's heap is set to 3GB, and the container is limited to 3.1GB, the application may crash without an explicit OOM in the logs due to memory shortage outside the heap — for example, on the stack, metaspace, native memory.

The Java process uses memory not only for the heap but also for:

  • Thread stacks
  • Metaspace (classes, metadata)
  • Buffers and native allocators

If the total of these areas plus the heap exceeds the container limit, the OS will kill the process due to OOM, but the JVM may not have time to record an OutOfMemoryError.

To fix this:

  • Reduce the heap size, for example to 2.5GB, to leave room for other areas.
  • Configure JVM parameters, for example -XX:MaxMetaspaceSize and thread stack size (-Xss).
  • Increase the container memory limit if possible.

Example configuration:

java -Xmx2500m -XX:MaxMetaspaceSize=256m -Xss512k -jar app.jar

And ensure that the container allocates more memory than the JVM's maximum total.