Skip to content
Latchkey

Bamboo "OutOfMemoryError: Java heap space" on the agent in CI

A JVM-based task, or the agent process itself, ran out of heap. The task dies with OutOfMemoryError, and if the agent JVM is the one that ran out, the agent may drop offline mid-build.

What this error means

The build log shows "java.lang.OutOfMemoryError: Java heap space" (or GC overhead limit exceeded), and the task fails or the agent disconnects during the build.

Bamboo
java.lang.OutOfMemoryError: Java heap space
    at ...
Failing task since return code of the command was 137.

Common causes

The build task heap is too small for the workload

A Maven/Gradle/Java task ran with default or low -Xmx and exceeded it while compiling or testing a large project.

The agent JVM or host ran out of memory

The agent process heap is undersized, or concurrent builds exhausted host memory, so the JVM raised OutOfMemoryError.

How to fix it

Raise the heap for the build task

  1. Set a larger heap for the build tool via its environment variable in the task.
  2. Confirm the agent host has enough physical memory for that heap.
  3. Re-run the build.
Terminal
export MAVEN_OPTS="-Xmx2g"
# or GRADLE_OPTS / JAVA_TOOL_OPTIONS in the task environment

Give the agent JVM more heap

Increase the remote agent JVM heap in its wrapper configuration so the agent process itself does not run out during heavy builds.

How to prevent it

  • Set explicit build-tool heap sizes sized to the project.
  • Provision agents with memory headroom for the heaviest builds.
  • Limit concurrent builds per agent to avoid host memory exhaustion.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →