Skip to content
Latchkey

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).

dotnet
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

  1. Lower test parallelism and free large objects between tests.
  2. Give the job a runner with more memory if the working set is genuinely large.
  3. For a one-off OOM under load with no leak, re-run; self-healing managed runners auto-retry transient resource aborts.
shell
dotnet test -- RunConfiguration.MaxCpuCount=2

How 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.

Frequently asked questions

What causes ""OutOfMemoryException" during tests"?
Tests load huge fixtures, never release large objects, or accumulate state across cases until memory is exhausted.
How do I fix "OutOfMemoryException" during tests?
Reduce memory pressure, then retry transient OOMs

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card