Skip to content
Latchkey

JVM "Could not reserve enough space for object heap" in CI

The JVM failed to even start because it could not reserve the heap you requested. The -Xmx (or a JAVA_OPTS/MAVEN_OPTS value) asks for more memory than the runner has, or exceeds a 32-bit JVM’s address space.

What this error means

The process never runs your code - it fails at VM initialization with Could not reserve enough space for ... object heap, often followed by Could not create the Java Virtual Machine.

JVM output
Error occurred during initialization of VM
Could not reserve enough space for 4194304KB object heap
# or
Error: Could not create the Java Virtual Machine.

Common causes

-Xmx exceeds available RAM

A -Xmx4g set in MAVEN_OPTS/GRADLE_OPTS/JAVA_TOOL_OPTIONS on a 2 GB runner cannot be reserved, so the VM aborts at startup.

32-bit JVM address-space ceiling

A 32-bit JVM cannot address more than ~2–4 GB regardless of physical RAM. Requesting a large heap on it fails to reserve contiguous space.

How to fix it

Lower -Xmx to fit the runner

Check the runner RAM and set a heap that fits with headroom. Inspect every env var that injects JVM args.

Terminal
free -m                       # see available RAM
echo "$MAVEN_OPTS $JAVA_TOOL_OPTIONS"   # find the oversized -Xmx
export MAVEN_OPTS="-Xmx1g"

Use a 64-bit JVM

Ensure the runner uses a 64-bit JDK so large heaps are addressable.

Terminal
java -XX:+PrintFlagsFinal -version | grep -i 64
java -version   # look for "64-Bit Server VM"

How to prevent it

  • Set JVM heap relative to the runner RAM, not a fixed large value copied between machines.
  • Audit MAVEN_OPTS/GRADLE_OPTS/JAVA_TOOL_OPTIONS for stale oversized -Xmx.
  • Always use a 64-bit JDK in CI.

Frequently asked questions

What causes ""Could not reserve enough space for object heap""?
A -Xmx4g set in MAVEN_OPTS/GRADLE_OPTS/JAVA_TOOL_OPTIONS on a 2 GB runner cannot be reserved, so the VM aborts at startup.
How do I fix "Could not reserve enough space for object heap"?
Check the runner RAM and set a heap that fits with headroom. Inspect every env var that injects JVM args.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card