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

**Code:** `OutOfMemoryException` · **Category:** .NET · **Seen on:** .NET

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

## 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

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/dotnet/outofmemoryexception)
