forked from dotnet/maui
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ios] fix memory leaks in
GestureRecognizers
Context: dotnet#20023 (comment) One of the underlying reasons `RadioButton` appears to leak, is that it happens to use a `TapGestureRecognizer` internally. When testing, @tj-devel709 and I found we could add pretty much *any* recognizer to a simple control like `BoxView`, and it would cause the `BoxView` to live forever. I could reproduce this in a new unit test that I setup for each type of gesture recognizer. `GesturePlatformManager.iOS.cs` had two "cycles": * `*Handler` -> ... -> `GesturePlatformManager` -> `*Handler` * `*GestureRecognizer` -> `GesturePlatformManager` -> `*GestureRecognizer` To fix these, we can make `GesturePlatformManager` not have strong references pointing *back* to its parent classes: * Make `_handler` a `WeakReference<IPlatformViewHandler>` * Make `_gestureRecognizers` a `ConditionalWeakTable` With these changes the tests pass, except for `PanGestureRecognizer`, which had a "closure" in using the `panRecognizer` variable. I fixed this one with: * `((PanGestureRecognizer)panGestureRecognizer)` as `panGestureRecognizer` was backed by a `WeakReference`.
- Loading branch information
1 parent
7639a2c
commit 8d65cde
Showing
2 changed files
with
67 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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