Skip to content
This repository has been archived by the owner on Apr 23, 2023. It is now read-only.

Context memory leak #175

Closed
rwrx opened this issue Mar 31, 2017 · 3 comments · Fixed by #190
Closed

Context memory leak #175

rwrx opened this issue Mar 31, 2017 · 3 comments · Fixed by #190
Assignees
Labels
Milestone

Comments

@rwrx
Copy link

rwrx commented Mar 31, 2017

I have found that context field variable inside FusedLocationProviderApiImpl is causing memory leaks for passed Context. It is on this line: https://github.com/mapzen/lost/blob/master/lost/src/main/java/com/mapzen/android/lost/internal/FusedLocationProviderApiImpl.java#L32. It is causing memory leaks due to FusedLocationApi static field variable inside LocationServices. I haven't much investigated which exactly was causing this, but I can look at it if you want.

@rwrx
Copy link
Author

rwrx commented Mar 31, 2017

I have also found that context field varible inside GeofencingApiImpl is causing memory leak for passed context: https://github.com/mapzen/lost/blob/master/lost/src/main/java/com/mapzen/android/lost/internal/GeofencingApiImpl.java#L30 . This memory leak is caused by static variable field GeofencingApi inside LocationServices. I believe that these leaks are caused by not setting to null contexts in both classes GeofencingApiImpl and FusedLocationProviderApiImpl when they was set by connect() method. So maybe just setting these contexts to null when disconnect() is called will fix them.

@ecgreb ecgreb added the bug label Apr 3, 2017
@ecgreb
Copy link
Collaborator

ecgreb commented Apr 3, 2017

Thanks for the report @rwrx !

We should consider using the application context and/or a WeakReference here similar to how the Context is handled in the Mapbox SDK.

https://github.com/mapbox/mapbox-java/blob/master/mapbox/libandroid-services/src/main/java/com/mapbox/services/android/location/LostLocationEngine.java

@rwrx
Copy link
Author

rwrx commented Apr 3, 2017

Yes, I agree, WeakReference can help with leaking Context. How can I help? :)

@ecgreb ecgreb added the ready label Apr 12, 2017
@ecgreb ecgreb added this to the 2.3 milestone Apr 27, 2017
@sarahsnow1 sarahsnow1 self-assigned this May 8, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants