PinnedBuffer causes large heap when used continuously for reading
We are collecting and reading a continuous session of trace data (in this case logs and metrics) from EventSource using TraceEvent. While this works correctly, and strictly speaking there is no memory leak, we are seeing a very large amount of PinnedBuffer objects, with pinned memory regions. This in turn causes the GC operations to not be able to compact memory properly and as a result the heap size increases. Most of the heap is free space.
Ideally, we would want PinnedBuffers to be determinstically cleaned up (unpinned) or use a pool of pinned buffers that gets rented and diposed as necessary, instead of constantly allocating a new pinned buffer.
Some RAW GC data
!dumpheap -type PinnedBuffer
Statistics:
MT Count TotalSize Class Name
7137a85bfbb8 2,071 66,272 Microsoft.Diagnostics.Tracing.EventPipe.PinnedBuffer
Total 2,071 objects, 66,272 bytes
!gchandles -type pinned
Statistics:
MT Count TotalSize Class Name
00007137a37e5ac8 1 24 System.Object
00007137a3a893f0 978 4528747 System.Byte[]
Total 979 objects
Thanks to @Maoni0 for the analysis, thanks to @noahfalk for the fix suggestion
@wiktork, did the change made by @noahfalk end up fixing this?
@brianrob The folks who originally reported this issue will be testing the fix with the updated payload.
Thanks @wiktork. Since we believe this is fixed in the current release, I'm going to close this issue. If you find that the issue is not resolved, just let me know and I can re-open it.
Hello @wiktork ,
Good Day!
I’ve been working closely with one of our customers who continues to experience the same issue.
Could you kindly confirm whether a resolution has been implemented? If not, would you be able to share an estimated timeline for when a fix is expected to be released?