elye / loaderviewlibrary

Library that enables TextView of ImageView to show loading animation while waiting for the text and image get loaded

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LoaderImageView leaks memory

passiondroid opened this issue · comments

LoaderImageView leaks memory as it holds the context of the activity.
Please check the below screenshot from Leakcanary

image

commented

It is unlikely LoaderImageView itself leaks. The mContext passed to it, is like any context pass to ImageView. LoaderImageView itself doesn't use the mContext, but the ImageView (which it inherits does). In normal case, the LoaderImageView (ImageView) would be destroy when HomeActivity is destroy.

The only possible exception is you have load some drawable object to the ImageView, here the object lives longer than HomeActivity. Hence this preventing ImageView (or LoaderImageView) from being destroy when HomeActivity is destroyed. And with that, the mContext it holds leaks.

Check out this blog post http://www.curious-creature.com/2008/12/18/avoid-memory-leaks-on-android/ by Roman Guy.