dotnet/orleans

PooledBuffer does not recycle memory pool objects

buzzers opened this issue · 0 comments

https://github.com/dotnet/orleans/blob/main/src/Orleans.Serialization/Buffers/PooledBuffer.cs#L342

    private SequenceSegment Grow(int sizeHint)
    {
        Commit();
        var newBuffer = SequenceSegmentPool.Shared.Rent(sizeHint);
        return WriteHead = newBuffer;
    }

Here, a new segment is directly obtained without checking whether WriteHead is null after commit.
However, the commit method will return directly when WriteHead is not null and there is no writing,
which causes the currently allocated WriteHead segment to be overwritten by the newly allocated segment without returning to the memory pool.
This should not cause correctness issues but may harm performance.