Diagnostics Allocations in ASP.NET Core
10/12/2025
Object Allocations
ASP.NET Core's Kestrel is optimized for high performance and scale. To achieve high performance, it reduces heap allocations by either pooling large objects or by allocating struct
s on the stack. By reducing allocations, the GC has less work to do. As pooled objects get promoted to Gen2 generation, the most common collections (Gen0 and Gen1) become cheaper as they contain fewer objects to handle. However, pooling is not entirely free:
it increases the Gen2 size and its corresponding collections
cross-generation references may require tracking references from Gen2 regions pointing to lower generation regions (for example, when a pooled object contains a reference to a newly allocated object).
One example is type Http2Stream
(or Http3Stream
), which corresponds to a request-response pair in a connection. As such objects are large, they are typically pooled. These objects may have a reference to the corresponding HttpContext
, which should be also pooled, otherwise it incurs an allocation or a cross-generation reference.