Skip to content

JMeter OutOfMemoryError Java heap space

Fix JMeter OutOfMemoryError Java heap space: raise heap, cut threads, disable View Results Tree, trim result saving, and split injectors. Symptom and fixes.

Difficulty
intermediate
Guide type
troubleshooting
Estimated read time
7 min read
Last verified version
Verified JMeter 5.6

OutOfMemoryError: Java heap space in JMeter

Section titled “OutOfMemoryError: Java heap space in JMeter”
  • JMeter exits or freezes with java.lang.OutOfMemoryError: Java heap space
  • Long GC pauses, injector becomes unresponsive
  • In containers: pod/container OOMKilled even without a clear Java stack
  • Often appears when increasing threads, enabling View Results Tree, or saving full responses

Official best practices stress lean injectors:

CauseDetail
Heap too small for threadsRoughly more concurrent threads → more live objects; default heap may be too low
View Results Tree / heavy listenersKeep detailed sample data in memory - debug only
Too many threads on one JVMNeed more engines (distributed) or lower concurrency
Saving too muchXML results, response data, large bodies
Heavy scriptsBeanShell/JavaScript on hot paths; prefer JSR223 Groovy with compile cache
Container limit below -Xmxcgroup kills the process (Docker/K8s)
  1. Switch to non-GUI for load

    Terminal window
    jmeter -n -t plan.jmx -l results.jtl -e -o report/
  2. Disable View Results Tree, View Results in Table, and other heavy listeners for the load run (best practices).

  3. Size heap for the injector using the Heap Estimator as a starting point; set HEAP / JVM_ARGS (for example -Xms512m -Xmx2048m) per your launch scripts, then restart JMeter.

  4. Reduce threads per engine; scale out with multiple CLI instances or remote workers rather than one huge JVM.

  5. Prefer CSV result files and only the saveservice fields you need (dashboard requirements).

  6. Replace expensive scripting with JSR223 + Groovy, cache compiled scripts, use vars.get("x") not embedded \${x} in cached scripts (best practices).

  7. In Docker/K8s: set memory limits above -Xmx plus native overhead.

  8. Re-test with a pilot; watch GC logs if problems continue.

ResourceUse when
Heap EstimatorStarting -Xmx guess
Thread CalculatorFewer threads if RPS allows
Distributed testingSpread load across engines
Docker / Kubernetescgroup OOM
Best practicesLean plan rules

Often it is the JMeter injector. Confirm with injector GC/heap metrics before blaming the SUT.

GUI rendering plus listeners keep more objects alive. Official guidance: use GUI to build, CLI for load.

It depends on threads, response sizes, scripting, and listeners. Start from the Heap Estimator, then validate under a pilot run.

On this page