Use applicationContext for Singleton Image Loader#3246
Conversation
|
Thank you very much for fixing this issue. I believe this PR should have resolved the problem. AppWatcher.objectWatcher.expectWeaklyReachable(this,"Watching for leaks from MainActivity")This should be called within Activity.onDestroy. If it is called in onCreate, then after approximately 5 seconds (I'm not entirely sure of the exact duration), if the Activity has not been destroyed, LeakCanary will consider that the Activity has a memory leak. In fact, if you have integrated LeakCanary, it will automatically perform the detection — there's no need to manually add anything. So, in practice, you just need to integrate LeakCanary, launch the Activity, and then exit it before the image finishes loading. LeakCanary will then detect any memory leaks. Once the issue is fixed, nothing will be reported. |
|
@KittenBall Okay I have tried again this time without adding any watcher manually, and I can confirm there is no more heap dumps when I exit the activity: I will update the PR description now, thank you! |
|
You are welcome, thank you. |
|
@colinrtwhite I need some help to review this when you get the chance ^^ |
|
@nishatoma Thanks for implementing this! Left a few comments then we should be good to merge. |
|
@colinrtwhite Thank you so much for the feedback, I have addressed all comments! |
This PR attempts to fix #3213 by using
applicationContextwhen fetchingImageLoader.This only affectsAndroidplatform. Non-Android platforms remains usingPlatformContextas is.Changelog
applicationContext()extension function.SingleImageLoader.ktto useapplicationContextfrom thePlatformContextif possible.Before and After breakpoint checking passed context via activity
Before and After LeakCanary dump
This is my first time using LeakCanary, so I would need help to verify if this is working as intended:
Before
After
Testing Procedure
KittenBalls instructions, I completely exited the app via back press before image loaded. And observed the heap dump.