Java "GC overhead limit exceeded" During Build - Fix Heap in CI
By Kaveh Alemi·Latchkey
The JVM aborted with GC overhead limit exceeded - it spent over 98% of recent time collecting garbage while recovering less than 2% of the heap. The heap is effectively full of live objects; GC is thrashing.
What this error means
A compile, test, or codegen step fails with java.lang.OutOfMemoryError: GC overhead limit exceeded. The build slows dramatically before failing as GC dominates wall-clock time.
The work needs more heap than -Xmx allows. As the heap fills with live objects, GC runs constantly but frees little, tripping the overhead limit.
Excessive allocation or retention
A test or task that retains large structures (big fixtures, accumulating collections) keeps too much live, so GC cannot reclaim enough to make progress.
Split very large tests or process data in streams/batches instead of loading it all.
Bound forked test JVM heap so each fork has adequate room.
Capture a heap dump on OOM and inspect the dominating retained objects.
How to prevent it
Size -Xmx to the live set, bound forked-JVM heaps, and avoid retaining large structures across a build step.
Frequently asked questions
What causes ""GC overhead limit exceeded""?
The work needs more heap than -Xmx allows. As the heap fills with live objects, GC runs constantly but frees little, tripping the overhead limit.
How do I fix "GC overhead limit exceeded"?
Give the JVM enough heap so GC is not thrashing.
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.