System.OutOfMemoryException during dotnet test in CI
An OutOfMemoryException in the test host means the process could not allocate the memory it needed. It is either a genuine problem (a leak, an unbounded buffer, excessive parallelism allocating too much at once) or transient runner pressure where the host happened to be starved on that run.
What this error means
The run throws System.OutOfMemoryException and the test host may abort. It can be deterministic (a leak) or intermittent (runner pressure).
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
The active test run was aborted.Common causes
A leak or unbounded allocation in tests
Tests load huge fixtures, never release large objects, or accumulate state across cases until memory is exhausted.
Too much parallelism for the runner
High test parallelism multiplies peak memory, exceeding what the runner has on a busy run.
How to fix it
Reduce memory pressure, then retry transient OOMs
- Lower test parallelism and free large objects between tests.
- Give the job a runner with more memory if the working set is genuinely large.
- For a one-off OOM under load with no leak, re-run; self-healing managed runners auto-retry transient resource aborts.
dotnet test -- RunConfiguration.MaxCpuCount=2How to prevent it
- Cap test parallelism to the runner memory budget.
- Dispose large resources and avoid accumulating fixtures across tests.
- Run CI on self-healing managed runners that retry transient resource aborts.