perfview icon indicating copy to clipboard operation
perfview copied to clipboard

PinnedBuffer causes large heap when used continuously for reading

Open wiktork opened this issue 1 year ago • 1 comments

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

wiktork avatar Aug 23 '24 04:08 wiktork

Thanks to @Maoni0 for the analysis, thanks to @noahfalk for the fix suggestion

wiktork avatar Aug 23 '24 05:08 wiktork

@wiktork, did the change made by @noahfalk end up fixing this?

brianrob avatar May 30 '25 03:05 brianrob

@brianrob The folks who originally reported this issue will be testing the fix with the updated payload.

wiktork avatar May 30 '25 15:05 wiktork

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.

brianrob avatar May 30 '25 23:05 brianrob

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?

Ravb50 avatar Nov 03 '25 08:11 Ravb50