Skip to content

Comments

[net7.0] [core] WeakEventManager.RemoveEventHandler() should clear subscriptions#13650

Merged
PureWeen merged 3 commits intonet7.0from
backport/pr-13333-to-net7.0
Mar 3, 2023
Merged

[net7.0] [core] WeakEventManager.RemoveEventHandler() should clear subscriptions#13650
PureWeen merged 3 commits intonet7.0from
backport/pr-13333-to-net7.0

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Mar 2, 2023

Backport of #13333 to net7.0

/cc @PureWeen @jonathanpeppers

Context: #12039
Context: https://github.com/Vroomer/MAUI-master-detail-memory-leak
Context: https://github.com/symbiogenesis/Maui.DataGrid/tree/memory-leak

Reviewing memory snapshots in the above apps, sometimes I would see
new `WeakEventManager+Subscription` objects be created and never go
away.

I noticed the `WeakEventManager.RemoveEventHandler()` method did not
remove any `Subscription` entries that it encountered were no longer
alive.

I could reproduce this problem in a test, and improved an existing
test to check this collection is cleared appropriately:

    readonly Dictionary<string, List<Subscription>> _eventHandlers = new();
This is closer to the standard `forr` snippet that has been around forever, just using `n` instead of `i`.
@PureWeen
Copy link
Member

PureWeen commented Mar 2, 2023

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@PureWeen PureWeen enabled auto-merge March 2, 2023 16:58
Subscription current = subscriptions[n];

if (current.Subscriber?.Target != handlerTarget || current.Handler.Name != methodInfo.Name)
if (current.Subscriber != null && !current.Subscriber.IsAlive)
Copy link
Contributor

Choose a reason for hiding this comment

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

Bummer this is a back port and is was not used in the original PR :/

@PureWeen
Copy link
Member

PureWeen commented Mar 3, 2023

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@PureWeen PureWeen merged commit d9e9c76 into net7.0 Mar 3, 2023
@PureWeen PureWeen deleted the backport/pr-13333-to-net7.0 branch March 3, 2023 13:17
@rmarinho
Copy link
Member

/backport to release/7.0.2xx

@github-actions
Copy link
Contributor Author

Started backporting to release/7.0.2xx: https://github.com/dotnet/maui/actions/runs/4469307465

@github-actions github-actions bot locked and limited conversation to collaborators Dec 12, 2023
@samhouts samhouts added the fixed-in-7.0.92 Look for this fix in 7.0.92! label Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

fixed-in-7.0.92 Look for this fix in 7.0.92!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants