android / location-samples

Multiple samples showing the best practices in location APIs on Android.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LocationCallback memory leak in LocationUpdates Sample

dromosys opened this issue · comments

Easy to reproduce, just clone https://github.com/android/location-samples/tree/master/LocationUpdates

edit build.gradle adding

debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.3'

and rotate orientation

HEAP ANALYSIS RESULT

1 APPLICATION LEAKS

References underlined with "~~~" are likely causes.
Learn more at https://squ.re/leaks.

248685 bytes retained by leaking objects
Displaying only 1 leak trace out of 2 with the same signature
Signature: df609756fcf03084a78ee1be43d59bae8d9e1767
┬───
│ GC Root: Global variable in native code

├─ com.google.android.gms.location.zzam instance
│ Leaking: UNKNOWN
│ ↓ zzam.zza
│ ~~~
├─ com.google.android.gms.location.zzx instance
│ Leaking: UNKNOWN
│ ↓ zzx.zzc
│ ~~~
├─ com.google.android.gms.location.sample.locationupdates.MainActivity$1 instance
│ Leaking: UNKNOWN
│ Anonymous subclass of com.google.android.gms.location.LocationCallback
│ ↓ MainActivity$1.this$0
│ ~~~~~~
╰→ com.google.android.gms.location.sample.locationupdates.MainActivity instance
​ Leaking: YES (ObjectWatcher was watching this because com.google.android.gms.location.sample.locationupdates.MainActivity received Activity#onDestroy() callback and Activity#mDestroyed is true)
​ key = 5e023255-8a06-482d-9cda-b4371f67d64d
​ watchDurationMillis = 6730
​ retainedDurationMillis = 1725

I'm seeing this issue too