MATLAB tried to allocate an array larger than the free memory on the runner. Hosted runners typically have 7 to 16 GB, far less than a workstation, so a computation that fits locally can exhaust CI memory.
What this error means
A run stops with "Out of memory. The likely cause is an infinite recursion within the program." or "Requested array exceeds the maximum possible variable size.", and MATLAB may be killed by the OS.
MATLAB
Error using zeros
Requested 200000x200000 (298.0GB) array exceeds maximum array size preference (63.9GB).
Diagnose it: which runtime is actually on PATH?
Runners ship multiple versions of most runtimes and select one through a version manager. When a setup action and a version file disagree, the resulting error is about your code rather than the version.
Terminal
which -a <runtime>
<runtime> --version
echo "PATH=$PATH" | tr ":" "\n" | head -20
# does a version file in the repo disagree with the workflow?
cat .tool-versions .nvmrc .ruby-version .python-version 2>/dev/null
Common causes
The allocation exceeds runner RAM
A dense array or an accidental broadcast produced a variable larger than the hosted runner has available.
Growing data in a loop
Repeated concatenation or an unbounded accumulation inflates memory until it exceeds the limit.
How to fix it
Reduce the footprint or the data size
Preallocate instead of growing arrays in a loop.
Use sparse matrices, chunking, or single precision where appropriate.
Scale down the CI dataset to a representative subset.
solve.m
A = spalloc(n, n, nnz_estimate); % sparse instead of dense zeros(n,n)
Run on a larger runner
For genuinely large jobs, target a self-hosted or larger runner with more RAM.
.github/workflows/ci.yml
jobs:build:runs-on:[self-hosted, high-memory]
How to prevent it
Preallocate arrays and avoid growing them in loops.
Use sparse or reduced-precision types for large data.
Size CI datasets to fit the runner or use a high-memory runner.
Frequently asked questions
What causes MATLAB "Out of memory" in CI?
There are 2 common causes: the allocation exceeds runner ram and growing data in a loop. A dense array or an accidental broadcast produced a variable larger than the hosted runner has available.
How do I fix MATLAB "Out of memory" in CI?
There are 2 fixes depending on which cause you have: reduce the footprint or the data size and run on a larger runner. Work through them in order, since the first is the most common.
What does MATLAB "Out of memory" in CI actually mean?
A run stops with "Out of memory.
How do I stop MATLAB "Out of memory" in CI happening again?
Preallocate arrays and avoid growing them in loops. The prevention section lists 3 changes that keep it from recurring.