Java "Could not reserve enough space for object heap" in CI
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.
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.
export MAVEN_OPTS="-Xmx1500m"
# Gradle: org.gradle.jvmargs=-Xmx1500m in gradle.propertiesLet the JVM size heap to the container
Use percentage-based sizing so the heap tracks the cgroup limit instead of a fixed value.
export JAVA_TOOL_OPTIONS="-XX:MaxRAMPercentage=70.0"How to prevent it
- Set
-Xmxbelow the runner/container memory, prefer-XX:MaxRAMPercentagein containers, and size runners to the build heap.