What is Microsoft.IO.RecyclableMemoryStream?
masterMicrosoft.IO.RecyclableMemoryStream is a high-performance replacement for System.IO.MemoryStream. It is designed to improve application performance and reduce Garbage Collection (GC) overhead by pooling underlying buffers instead of pooling the stream objects themselves.
Key Benefits:
- Reduces LOH Allocations: Uses pooled buffers to avoid Large Object Heap fragmentation.
- Lower GC Pressure: Reduces Gen 2 collections and GC pause times.
- Memory Safety: Includes bounded pool sizes to prevent memory leaks and fragmentation.
- High Performance: Supports modern memory types like
Span<byte>,ReadOnlySpan<byte>,ReadOnlySequence<byte>, andMemory<byte>. - Observability: Provides metrics, logging, and debug features like call stack recording for leaked streams.