-
Notifications
You must be signed in to change notification settings - Fork 401
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
Fix memory leak on touchBehavior android #2113
Conversation
src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors/Touch/TouchBehavior.android.cs
Outdated
Show resolved
Hide resolved
3dfa8be
to
5ceea9f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Pedro!!
Just FYI - I removed WeakWrapper
since we were only using it once in TouchBehavior.android.cs
; we can always add it later if we end up relying on WeakReference<T>
more.
I also updated Dispose(bool)
to properly dispose of the WeakReference.Target
be setting it to null
.
`Install Tizen Workload` now fails fast
@brminnick the Dispose method isn't being called, because of that I used the |
Is this a bug in I see we dispose our instance of this class (
Two thoughts:
|
I'm not sure if it's a bug or the way the BaseBehavior works, I assumed isn't a bug. The So, there's no bug in the .net-android
not sure about this one... But in this case, it doesn't make any difference just add more code that will not be executed |
Hi, protected override void OnDetachedFrom(VisualElement bindable, AView platformView)
{
base.OnDetachedFrom(bindable, platformView);
view = platformView;
if (Element is null)
{
return;
}
... We exiting when I think that this null check is spare. |
Description of Change
This PR fixes the memory leak on Android's implementation of TouchBehavior, and adds a new type
WeakWrapper
, that is to help maintainer and contributors to create and useWeakReference
types.From my investigations the issue was because of the strong
TouchBehavior
reference inside theAccessibilityListener
, changing to be aWeakReference
fixes the leak, as you can see in the video below.Screenbits.2024-08-11_162437.mp4
also, from the video, you can see it will say there's a leak, but in fact the object will take a while to be free, probably it implements a
Finalizer
which will make it live longer. Just saying, because some user can complain about it.Linked Issues
PR Checklist
approved
(bug) orChampioned
(feature/proposal)main
at time of PRAdditional information