OutOfMemoryException 🟪 .NET

System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown

The process couldn’t allocate memory — large in-memory data, leaks, 32-bit process limits, or container memory limits.

Seen on: .NET

Meaning

Loading whole files/tables into memory, huge strings/StringBuilders, caching without limits, or running as 32-bit (Prefer 32-bit) cause it. In containers the GC heap limit follows the memory limit.

Common causes

  • Loading large datasets/files fully into memory
  • Memory leak (static caches, event handlers)
  • 32-bit process (Prefer 32-bit)
  • Container memory limit

⚡ Quick fix

  1. Stream data (IAsyncEnumerable, FileStream)
  2. Use dotnet-counters/dotnet-dump to find what grows
  3. Build as 64-bit; raise container limit if justified

Detailed fix by platform

Shell

  1. csharp
    dotnet-counters monitor -p <pid> System.Runtime
    dotnet-dump collect -p <pid>

How to diagnose

  1. Growth — GC heap over time
  2. Bitness — 32-bit?
  3. Limits — Container memory

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.