MATLAB "Out of memory" in CI
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.
Error using zeros
Requested 200000x200000 (298.0GB) array exceeds maximum array size preference (63.9GB).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.
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.
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.