Fix memory leak on touchBehavior android#2113
Conversation
3dfa8be to
5ceea9f
Compare
TheCodeTraveler
left a comment
There was a problem hiding this comment.
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 useWeakReferencetypes.From my investigations the issue was because of the strong
TouchBehaviorreference inside theAccessibilityListener, changing to be aWeakReferencefixes 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
Finalizerwhich will make it live longer. Just saying, because some user can complain about it.Linked Issues
PR Checklist
approved(bug) orChampioned(feature/proposal)mainat time of PRAdditional information