Skip to content
Latchkey

JMeter "java.lang.OutOfMemoryError: Java heap space" in CI

JMeter runs on the JVM with a default heap that is often too small for high thread counts or memory-hungry listeners. "OutOfMemoryError: Java heap space" aborts the run, usually because a GUI-style listener is buffering every sample.

What this error means

The non-GUI run dies with "java.lang.OutOfMemoryError: Java heap space" in jmeter.log, frequently when a View Results Tree or heavy assertion is enabled during load.

JMeter
Uncaught Exception java.lang.OutOfMemoryError: Java heap space in thread Thread[...]
Consider using JVM options -Xms and -Xmx to allocate more memory.

Common causes

Default heap too small for the thread count

The bundled JMeter heap cannot hold the state for large thread groups plus in-flight responses.

Memory-heavy listeners left enabled

View Results Tree and similar listeners buffer every sample in memory and must be disabled for load runs.

How to fix it

Raise the JMeter heap

Set HEAP (or edit the jmeter launcher) before the non-GUI run to give the JVM more space.

Terminal
export HEAP="-Xms1g -Xmx4g"
jmeter -n -t plan.jmx -l results.jtl

Disable GUI listeners for load runs

  1. Remove or disable View Results Tree and Results Tree listeners in the plan.
  2. Write results to a JTL file with a Simple Data Writer instead.
  3. Run headless with -n so no GUI buffering occurs.
Terminal
jmeter -n -t plan.jmx -l results.jtl -e -o report/

How to prevent it

  • Set HEAP -Xmx to match the thread count before the run.
  • Disable memory-heavy listeners in non-GUI load tests.
  • Write results to JTL rather than buffering in a tree listener.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →