Skip to content
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

🐞 Memory leak in GoogleLocationEngineImpl #562

Open
yunikkk opened this issue Feb 21, 2022 · 0 comments
Open

🐞 Memory leak in GoogleLocationEngineImpl #562

yunikkk opened this issue Feb 21, 2022 · 0 comments
Labels

Comments

@yunikkk
Copy link
Contributor

yunikkk commented Feb 21, 2022

Configuration

  • SDK Version mapbox-android-core 5.0.0

Steps to Reproduce
Discovered the issue while debugging maps-android leak.

LocationCallback passed to GoogleLocationEngineImpl.requestLocationUpdates leaks after GoogleLocationEngineImpl.removeLocationUpdates is called.

The issue has long story behind, raised here, reworked here and the official following with the documented recommendation to avoid leaks using WeakReferences here implemented here.

Actually the issue with FusedLocationApi leaking listeners is tracked for a long time at 1, 2 and Google claims it will be resolved in the upcoming version 20 of Google play services library.

At the same time it seems that we can apply an easy fix that would make all the workarounds with WeakReferences unneeded.

This is how the leak path look like :
image

Obfuscated gms.location.zzx holds reference to the instance of LocationCallback that is our GoogleLocationEngineCallbackTransport instance, which in turn holds private final LocationEngineCallback<LocationEngineResult> callback that is actual callback passed by user. It seems we can just reset this field to null when removeLocationUpdates is called in addition to actual removal from the FusedLocationApis.
So it would still leak the GoogleLocationEngineCallbackTransport, but not the external callback passed by users (making activity or other big leaks not possible at all).

Expected
No leaks, happy users :)

Logging
Please attach logs or error messages

@yunikkk yunikkk added the bug label Feb 21, 2022
@yunikkk yunikkk changed the title 🐞 Bug Summary 🐞 Memory leak in GoogleLocationEngineImpl Feb 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant