huynhsontung / Screenbox

LibVLC-based media player for the Universal Windows Platform
GNU General Public License v3.0
1.11k stars 44 forks source link

fix: cache pages to avoid system memory leak #400

Closed huynhsontung closed 4 months ago

huynhsontung commented 5 months ago

Update: Memory leak is due to pages not unregistering the handler for view model's PropertyChanged events when navigating away. The ViewModel keeps a hard reference to the Page, so somehow both cannot be GC.

Looks like Pages don't get efficiently cleaned up when they are navigated away from. New Page instances are created on every navigation and never get properly released. It's confirmed to be a system-level memory leak. 🤦 Set NavigationCacheMode to Enabled can fix that.

https://learn.microsoft.com/en-us/answers/questions/111194/memory-leak-on-uwp-with-target-versions-10-0-17763 https://github.com/microsoft/microsoft-ui-xaml/issues/934 https://github.com/microsoft/microsoft-ui-xaml/issues/3597