Open sebastien-marichal opened 1 month ago
Left quiet here is that the ArrayPool<byte>.Shared.Return()
call is not in a finally
block. This is not wrong but how it should be (assuming that an exception is expected to be rare), since it reduces overhead. Not returning arrays to ArrayPool<T>.Shared
does not cause leaks, but provably never returning a particular array is of course wrong.
MemoryPool<T>.Rent()
returns an object that implements IDisposable
and should be disposed of. It should be assumed that not disposing may cause leaks, so using
or finally
should be used. Given that the returned object tends to be a new allocation (albeit a small one), there seems little reason to micro-optimize away a finally
block.
Buffers allocated using buffer pools such as ArrayPool should be returned after usage.
Noncompliant example
Compliant example
Notes
MemorePool does not have a
Return
and needs more investigation.