[Libav-user] How to profile libavXXX with only the .dll on Windows?

Wladislav Artsimovich ffmpeg at frost.kiwi
Fri Mar 31 11:52:44 EEST 2023

Dear libav-users,

concerning a memory leak I tried to diagnose in Thread "[Libav-user] How 
to free an AVBuffer?", I have the following block causing a memory leak 
of 20MB per 100.000 frames, as reported by the Visual Studio Performance 
Profiler [1 - VisualStudio Performance Profiler.png]. With this block 
commented out, (and just `ffmpeg.avcodec_send_frame();` ) everything is 
fine though.
fixed (byte* pMessageData = message)
     sideData = ffmpeg.av_frame_new_side_data(&frame, 
AVFrameSideDataType.AV_FRAME_DATA_SEI_UNREGISTERED, (ulong)message.Length);
     System.Buffer.MemoryCopy(pMessageData, sideData->data, 
(ulong)message.Length, (ulong)message.Length);

The project I'm working on is written in C#, and calls the FFmpeg .dlls 
via FFmpeg.AutoGen as "unmanaged code". As such I am unable to debug it 
in a meaningful way. I compiled everything along the way with debug 
symbols (FFmpeg, FFmpeg.AutoGEN, My Project etc.), in the hopes, that 
some debugging tool could tell me what's going on, but still the 
profiler doesn't give exact information, even though it detects the 
leaking allocation count and size. [2 - Memory Comparison.png]

I also tried taking a look with a lower-level debugger. I captured the 
process using Windows Event Tracing and analyzed the Heap using Windows 
Performance Analyzer. And whilst it can see the memory leak happening 
with associated addresses, I fail to understand the origin. [3 - Windows 
Performance Analyzer.png]

Lest recreating my program structure in C and debugging that, is there a 
way look into what the libavXXX.dlls are doing to find the specific 
origin of my memory leak?

Best regards,

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 1 - VisualStudio Performance Profiler.png
Type: image/png
Size: 39387 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20230331/b502ef8b/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 2 - Memory Comparison.png
Type: image/png
Size: 38409 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20230331/b502ef8b/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 3 - Windows Performance Analyzer.png
Type: image/png
Size: 61943 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20230331/b502ef8b/attachment-0002.png>

More information about the Libav-user mailing list