Java "Could not reserve enough space for object heap" in CI
By Kaveh Alemi·Latchkey
The JVM failed to start because it could not reserve the requested heap. The -Xmx value is larger than the memory available to the process, so the VM aborts before running anything.
What this error means
A Java step fails at JVM startup with Error occurred during initialization of VM: Could not reserve enough space for ... object heap. No application output appears - the VM never initialized.
java runtime
Error occurred during initialization of VM
Could not reserve enough space for 4194304KB object heap
##[error]Process completed with exit code 1.
Common causes
-Xmx larger than available RAM
A -Xmx4g on a runner or container with less than 4 GB free cannot reserve the heap, so the JVM refuses to start.
Container memory limit below the requested heap
A cgroup memory limit smaller than -Xmx (e.g. a 2 GB container asked for a 3 GB heap) causes the reservation to fail at startup.
How to fix it
Lower -Xmx to fit the runner
Set a heap that fits within the available memory, leaving headroom for the OS.
Terminal
export MAVEN_OPTS="-Xmx1500m"
# Gradle: org.gradle.jvmargs=-Xmx1500m in gradle.properties
Let the JVM size heap to the container
Use percentage-based sizing so the heap tracks the cgroup limit instead of a fixed value.
Set -Xmx below the runner/container memory, prefer -XX:MaxRAMPercentage in containers, and size runners to the build heap.
Frequently asked questions
What causes ""Could not reserve enough space for ... object heap""?
A -Xmx4g on a runner or container with less than 4 GB free cannot reserve the heap, so the JVM refuses to start.
How do I fix "Could not reserve enough space for ... object heap"?
Set a heap that fits within the available memory, leaving headroom for the OS.
Can Latchkey fix this automatically?
Yes. Latchkey runs your GitHub Actions on managed runners that detect this failure, apply the fix, and retry the job automatically - self-healing is on by default.