Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[windows] fix memory leak in MauiWinUIWindow #23327

Merged
merged 2 commits into from
Jul 4, 2024

Commits on Jul 2, 2024

  1. [windows] fix memory leak in MauiWinUIWindow

    Fixes: dotnet#22973
    Context: https://github.com/danielancines/memory-leak-dotnet8-maui
    
    After reviewing the above sample app, I found that the
    `MauiWinUIWindow` class was not ever going away. I could see it being
    held by `NavigationRootManager`:
    
    * `Microsoft.Maui.MauiWinUIWindow` ->
      * `Microsoft.Maui.Platform.NavigationRootManager` ->
        * `Windows.Foundation.TypedEventHandler<Microsoft.UI.Xaml.Controls.NavigationView, Microsoft.UI.Xaml.Controls.NavigationViewBackRequestedEventArgs>`
    
    After some trial and error, I found that simply changing
    `NavigationRootManager`'s `_platformWindow` field a `WeakReference`
    "untangles" things, and the sample no longer leaks `MauiWinUIWindow`
    instances.
    
    Unfortunately, I was not able to write a passing test for this issue.
    No matter what I tried, the platform `Window` is kept alive by a
    "strong handle". But taking a snapshot after the test ends, it goes
    away?
    
    I still thing the test is useful, as it verifies the other objects.
    jonathanpeppers committed Jul 2, 2024
    Configuration menu
    Copy the full SHA
    3ea9bf2 View commit details
    Browse the repository at this point in the history

Commits on Jul 3, 2024

  1. Fix test on Android

    jonathanpeppers committed Jul 3, 2024
    Configuration menu
    Copy the full SHA
    c19eb41 View commit details
    Browse the repository at this point in the history