SuRGeoNix / Flyleaf

Media Player .NET Library for WinUI 3/ WPF/WinForms (based on FFmpeg/DirectX)
GNU Lesser General Public License v3.0
715 stars 101 forks source link

WinUI Memory Leak & Possible Fix #416

Closed airtaxi closed 9 months ago

airtaxi commented 9 months ago

I'm making the video camera related application like below: 297656366-dfc036d2-098f-489a-89fe-3a89b3fc5e12

Since it uses multiple camera feeds, I noticed that FlyleafLib.Controls.WinUI has a memory leak problem.

The image below is a memory usage screenshot of my program after creating 10 instances of FlyleafHost. image

It's over 600+mb, and if I comment out the "Player" allocation code from Flyleaf Host, it doesn't cause the memory leak problem.

After some investigation, I found that if I add the lines of code highlighted below, the memory leak doesn't happen anymore. image image

Below is the screenshot of my application with the same condition after adding the two lines of code above. After

Edit: removed CI/BI

SuRGeoNix commented 9 months ago

Hi @airtaxi and thanks for the finding. SwapChain release will cause issues but for WinUI it seems to work fine now. The issue comes from the SwapChainPanel that keeps a reference inside it and it should be disposed but currently using a single instance for the template.