Developer knowledge network · moderated exchange

Сообщество UnreliableCode

Сообщество разработчиков, обратного проектирования и кодирования

Discussion

Understanding .NET Garbage Collection Generations (Gen 0, Gen 1, Gen 2) and the Large Object Heap (LOH) [StackOverflow Architecture Guide]

gc_internals_guy
.NET GC Specialist
MEMBER
Представитель: 101
Дата присоединения: Nov 2020
Сообщения: 1
Спасибо: 48
1 месяцев назад · Jul 6, 2026 11:58 AM
#1

How the .NET generational Garbage Collector optimizes memory management:

  • Gen 0: Short-lived objects (temporary variables, loop buffers). Collected frequently in sub-millisecond pauses.
  • Gen 1: Buffer zone for objects that survived Gen 0.
  • Gen 2: Long-lived objects (static singletons, cache dictionaries). Full GC collections are expensive.
  • Large Object Heap (LOH): Objects $\ge 85,000$ bytes are allocated directly on LOH to avoid copying costs during compaction, but can cause address space fragmentation.
  • Pinned Object Heap (POH): Objects pinned for native interop to avoid GC compaction barriers.
dotnet_runtime_architect
.NET Core Specialist
MEMBER
Представитель: 103
Дата присоединения: Apr 2018
Сообщения: 40
Спасибо: 24
1 месяцев назад · Jul 6, 2026 3:03 PM
#2

Allocating large buffers repeatedly on the LOH is the leading cause of OutOfMemoryException crashes in 32/64-bit .NET services.

profiler_pat
Performance Hunter
MEMBER
Представитель: 146
Дата присоединения: Aug 2019
Сообщения: 33
Спасибо: 31
1 месяцев назад · Jul 7, 2026 3:15 AM
#3

Always use ArrayPool<byte>.Shared.Rent() for buffers $>85\text{KB}$ to keep them off the LOH free lists!