Haskell GHC out of memory in CI
GHC ran out of memory while compiling, or the OS OOM killer terminated it. Heavy optimization of a large module, parallel builds, or type-level code can exceed a runner with limited RAM.
What this error means
A build fails with "ghc: out of memory (requested ... bytes)", "failed to allocate", or a step that ends abruptly with the process "Killed" (exit 137) during compilation.
Haskell
ghc: out of memory (requested 1048576 bytes)
<no location info>: error:
ghc: out of memory
Process exited with code: ExitFailure 251Common causes
Optimization of a large module exceeds RAM
Compiling a big module at -O2, or with heavy type-level computation, can use more memory than a small runner provides.
Too much build parallelism
Building many packages or modules at once multiplies peak memory and tips the runner into OOM.
How to fix it
Cap the GHC heap and reduce parallelism
- Limit the GHC RTS heap with
+RTS -Mso it fails gracefully or stays bounded. - Reduce build jobs so peak memory is lower.
- Re-run the build.
Terminal
cabal build all --ghc-options="+RTS -M3g -RTS" -j1Lower the optimization level for CI
Build heavy modules at a lower optimization level to cut compile-time memory.
Terminal
stack build --fastHow to prevent it
- Cap the GHC heap and build jobs on memory-limited runners.
- Use lower optimization in CI where runtime speed does not matter.
- Cache build artifacts so fewer modules recompile per run.
Related guides
Haskell stack "While building package" in CIFix stack "While building package X ... Process exited with code: ExitFailure" in CI - a dependency or your p…
Haskell GHC "Couldn't match expected type" in CIFix GHC "Couldn't match expected type X with actual type Y" in CI - a type error where an expression has a di…
Haskell cabal "Could not resolve dependencies" in CIFix cabal "Could not resolve dependencies" in CI - the solver found no install plan because version constrain…