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

[net7.0] Memory Leak: MAUI-Windows are not garbage-collected after destroy of MainActivity #16240

Merged
merged 1 commit into from Jul 20, 2023

Conversation

hartez
Copy link
Contributor

@hartez hartez commented Jul 19, 2023

Backport of #16045 to net7.0

/cc @jonathanpeppers

Since ac16ce6 was merged, I found several tests related to `Window`
fail on Windows with:

    InvalidOperationException: MauiContext is null.

In this case, `AlertManager.Unsubscribe()` is called after
`Window.Handler` is null:

    internal IMauiContext MauiContext =>
        Handler?.MauiContext ?? throw new InvalidOperationException("MauiContext is null.");

I updated `AlertManager.Unsubscribe()` on each platform to check
for this case and `return` instead of throwing an exception.

I am not sure if regular apps could ever hit this issue or just the
DeviceTests. .NET MAUI project templates seemed OK, so I think this
might be due to how `CreateHandlerAndAddToWindow()` works in tests?
Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one does seem pretty safe to service.

It looks like it has the two required changes:

@rmarinho rmarinho merged commit 0013ad4 into net7.0 Jul 20, 2023
30 checks passed
@rmarinho rmarinho deleted the backport/pr-16045-to-net7.0 branch July 20, 2023 14:22
@github-actions github-actions bot locked and limited conversation to collaborators Dec 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants