[net7.0] [core] WeakEventManager.RemoveEventHandler() should clear subscriptions#13650
Merged
[net7.0] [core] WeakEventManager.RemoveEventHandler() should clear subscriptions#13650
Conversation
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`.
jonathanpeppers
approved these changes
Mar 2, 2023
Member
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
mandel-macaque
approved these changes
Mar 2, 2023
| Subscription current = subscriptions[n]; | ||
|
|
||
| if (current.Subscriber?.Target != handlerTarget || current.Handler.Name != methodInfo.Name) | ||
| if (current.Subscriber != null && !current.Subscriber.IsAlive) |
Contributor
There was a problem hiding this comment.
Bummer this is a back port and is was not used in the original PR :/
Member
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
rmarinho
approved these changes
Mar 3, 2023
Member
|
/backport to release/7.0.2xx |
Contributor
Author
|
Started backporting to release/7.0.2xx: https://github.com/dotnet/maui/actions/runs/4469307465 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #13333 to net7.0
/cc @PureWeen @jonathanpeppers