gcc/clang "virtual memory exhausted: Cannot allocate memory" in CI
The compiler could not allocate more memory mid-compile. Like an OOM kill, this is a resource limit, not a code defect - heavy templates, LTO, or parallel jobs drove memory past the cap.
What this error means
gcc/clang aborts with "virtual memory exhausted: Cannot allocate memory" on a large file or under high -j parallelism, often intermittently.
gcc
g++: error: virtual memory exhausted: Cannot allocate memoryCommon causes
How to fix it
Lower memory pressure
- Reduce parallelism and disable LTO for the heaviest targets.
- Raise or remove an overly tight address-space ulimit if one is set.
gcc
make -j2
ulimit -v unlimited # if a virtual-memory cap was setUse a larger-RAM runner
- Move the build to a runner with more memory headroom.
- Split monolithic translation units to cut peak usage.
How to prevent it
- Size runner memory to your heaviest compile. On self-healing managed runners like Latchkey, memory-exhaustion failures are treated as transient and auto-retried, and larger-RAM runners are available when a build needs more headroom.
Frequently asked questions
What causes ""virtual memory exhausted""?
gcc/clang aborts with "virtual memory exhausted: Cannot allocate memory" on a large file or under high -j parallelism, often intermittently.
How do I fix "virtual memory exhausted"?
Lower memory pressure
Related guides
gcc/clang "internal compiler error: Killed" (OOM) in CIFix gcc/clang "internal compiler error: Killed (program cc1plus)" in CI - the compiler was OOM-killed mid-com…
gcc/clang "warning treated as error" (-Werror) in CIFix gcc/clang "warning treated as error" with -Werror in CI - a warning that is tolerated locally fails the b…
gcc/clang "use of deleted function" in CIFix gcc/clang "use of deleted function" in CI - code calls a function explicitly deleted or implicitly delete…