ogaclejapan / Qiitanium

Qiitanium is an unofficial Android application of Qiita
MIT License
250 stars 51 forks source link

LeakCanary reporting a leak in ArticleFragment #6

Open vladp opened 8 years ago

vladp commented 8 years ago

Hello, I apologize in advance -- if this is not the right venue to report the issue and ask for help. I am using your application to teach myself android programming. I think your application combines best architecture practices (clean architecture concept) with the good use of Dagger 2 and Rx programming techniques -- that are necessary to build industrial strength android apps.

As I progress through the code, I noticed that LeakCanary is reporting leaks (this one below happens simply after clicking on a particular article and then going back (clicking the back button on top a few times).

Would like to ask if you had observed this behaviour in your development environment and and if yes, what did you attribute this leak to?

thank you in in advance


12-27 00:38:21.987 4353-4361/com.ogaclejapan.qiitanium.dev W/art: Suspending all threads took: 49.651ms 12-27 00:38:22.088 4353-4380/com.ogaclejapan.qiitanium.dev I/art: Explicit concurrent mark sweep GC freed 2037(120KB) AllocSpace objects, 1(36KB) LOS objects, 8% free, 21MB/23MB, paused 3.903ms total 126.901ms 12-27 00:38:34.911 4353-4361/com.ogaclejapan.qiitanium.dev W/art: Suspending all threads took: 104.984ms 12-27 00:38:36.048 4353-9002/com.ogaclejapan.qiitanium.dev D/LeakCanary: In com.ogaclejapan.qiitanium.dev:0.2.1-dev:4. * com.ogaclejapan.qiitanium.presentation.fragment.ArticleFragment has leaked: * GC ROOT static com.ogaclejapan.qiitanium.domain.model.Users.instances * references java.util.WeakHashMap.elementData * references array java.util.WeakHashMap$Entry[].[3] * references java.util.WeakHashMap$Entry.value * references com.ogaclejapan.qiitanium.domain.model.User.thumbnailUrl * references com.ogaclejapan.rx.binding.RxProperty.subject * references rx.subjects.BehaviorSubject.state * references rx.subjects.SubjectSubscriptionManager.state * references rx.subjects.SubjectSubscriptionManager$State.observers * references array rx.subjects.SubjectSubscriptionManager$SubjectObserver[].[3] * references rx.subjects.SubjectSubscriptionManager$SubjectObserver.actual * references rx.observers.SafeSubscriber.actual * references rx.Observable$33.val$observer (anonymous class extends rx.Subscriber) * references com.ogaclejapan.rx.binding.RxProperty.subject * references rx.subjects.BehaviorSubject.state * references rx.subjects.SubjectSubscriptionManager.state * references rx.subjects.SubjectSubscriptionManager$State.observers * references array rx.subjects.SubjectSubscriptionManager$SubjectObserver[].[0] * references rx.subjects.SubjectSubscriptionManager$SubjectObserver.actual * references rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.child * references rx.observers.SafeSubscriber.actual * references rx.Observable$32.val$onNext (anonymous class extends rx.Subscriber) * references com.ogaclejapan.rx.binding.RxWeakRef$1.val$action (anonymous class implements rx.functions.Action1) * references com.ogaclejapan.qiitanium.presentation.fragment.ArticleAboutFragment$1.this$0 (anonymous class extends com.ogaclejapan.rx.binding.RxAction) * references com.ogaclejapan.qiitanium.presentation.fragment.ArticleAboutFragment.viewModelHolder * references com.ogaclejapan.qiitanium.presentation.activity.ArticleActivity.fragmentManager * references android.app.FragmentManagerImpl.mAdded * references java.util.ArrayList.array * references array java.lang.Object[].[0] * leaks com.ogaclejapan.qiitanium.presentation.fragment.ArticleFragment instance 12-27 00:38:36.076 4353-4380/com.ogaclejapan.qiitanium.dev I/art: hprof: heap dump "/data/data/com.ogaclejapan.qiitanium.dev/files/suspected_leak_heapdump.hprof" starting... 12-27 00:38:39.225 4353-4380/com.ogaclejapan.qiitanium.dev I/art: hprof: heap dump completed (33MB) in 3.148s 12-27 00:38:39.238 4353-4353/com.ogaclejapan.qiitanium.dev D/AppActivityLifecycleCallbacks: com.ogaclejapan.qiitanium.presentation.activity.TopActivity@148819d6 ⟳ onActivityStarted 12-27 00:38:39.238 4353-4353/com.ogaclejapan.qiitanium.dev D/AppActivityLifecycleCallbacks: com.ogaclejapan.qiitanium.presentation.activity.TopActivity@148819d6 ⟳ onActivityResumed 12-27 00:38:39.275 4353-4418/com.ogaclejapan.qiitanium.dev W/EGL_emulation: eglSurfaceAttrib not implemented 12-27 00:38:39.275 4353-4418/com.ogaclejapan.qiitanium.dev W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa1703520, error=EGL_SUCCESS 12-27 00:38:39.479 4353-4380/com.ogaclejapan.qiitanium.dev I/art: Explicit concurrent mark sweep GC freed 5787(400KB) AllocSpace objects, 0(0B) LOS objects, 15% free, 21MB/25MB, paused 18.195ms total 191.144ms 12-27 00:38:40.010 4353-4361/com.ogaclejapan.qiitanium.dev W/art: Suspending all threads took: 314.460ms 12-27 00:38:43.811 4353-4353/com.ogaclejapan.qiitanium.dev D/AppActivityLifecycleCallbacks: com.ogaclejapan.qiitanium.presentation.activity.TopActivity@148819d6 ⟳ onActivityPaused 12-27 00:38:44.000 4353-4353/com.ogaclejapan.qiitanium.dev D/AppActivityLifecycleCallbacks: com.ogaclejapan.qiitanium.presentation.activity.TopActivity@148819d6 ⟳ onActivitySaveInstanceState 12-27 00:38:44.001 4353-4353/com.ogaclejapan.qiitanium.dev D/AppActivityLifecycleCallbacks: com.ogaclejapan.qiitanium.presentation.activity.TopActivity@148819d6 ⟳ onActivityStopped 12-27 00:38:44.362 4353-4361/com.ogaclejapan.qiitanium.dev W/art: Suspending all threads took: 134.083ms 12-27 00:38:45.352 4353-4361/com.ogaclejapan.qiitanium.dev W/art: Suspending all threads took: 21.056ms

ogaclejapan commented 8 years ago

Thank you for reporting issue.

It is the wrong use of the WeakHashMap.

Hash table based implementation of the Map interface, with weak keys.