Skip to content
Latchkey

Gradle "The Daemon will be stopped ... after the build due to low heap space" - Fix in CI

Gradle detected its daemon was nearly out of heap and announced it will stop the daemon after the build to avoid memory pressure. The build may still pass, but the daemon is recycled every run (no warm reuse) and is one spike away from an OutOfMemoryError.

What this error means

The log shows The Daemon will be stopped at the end of the build after running out of JVM heap space or expiring Daemon because JVM heap space is exhausted. Builds are slow because the daemon never stays warm; a slightly bigger build OOMs.

gradle
> Task :test
The message received from the daemon indicates that the daemon has disappeared.
...
The Daemon will be stopped at the end of the build after running out of JVM
heap space (low heap space detected; consider increasing org.gradle.jvmargs)

Common causes

Daemon heap too small for the build

The default -Xmx is below what compilation, kapt, or large test runs need, so the daemon repeatedly nears exhaustion.

Memory-heavy plugins or codegen

Annotation processing, shadow/jib packaging, or large dependency graphs push heap use past the limit.

Undersized runner

A small runner cannot give the daemon enough RAM, so even a modest build trips the low-heap guard.

How to fix it

Raise the daemon heap

Give the Gradle daemon more heap and metaspace via gradle.properties.

properties
# gradle.properties
org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=1g -XX:+HeapDumpOnOutOfMemoryError

Cap test/worker forks

Bound forked memory so parallel test workers do not starve the daemon.

gradle
test {
  maxHeapSize = '1g'
  maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
}

Run on a larger runner

Match runner RAM to the build so the daemon stays warm.

yaml
# choose a higher-memory runner for heavy Gradle builds

How to prevent it

  • Set an explicit org.gradle.jvmargs heap sized to your build.
  • Bound test fork count and per-fork heap.
  • Right-size runners for memory-heavy Gradle builds.

Frequently asked questions

What causes ""Daemon will be stopped ... low heap""?
The default -Xmx is below what compilation, kapt, or large test runs need, so the daemon repeatedly nears exhaustion.
How do I fix "Daemon will be stopped ... low heap"?
Give the Gradle daemon more heap and metaspace via gradle.properties.
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.

Related guides

References

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