I've been getting random ( out of memory ) crashes in my app so I started to analyze my heap. I noticed that if I go from Activity A to Activity B, the heap increases ( due to lazy loading many images ) from 27 MB to 35 MB. However, when I finish() the activity B to return to Activity A, the heap size keeps the same even with GC operation !!
The annoying thing is that going to activity B one more time again increases the heap to 42 MB. I can do this as may times and the heap will only keep increasing.
This is the lazy images loading library I am using:
LazyList https://github.com/thest1/LazyList
These are screenshots of the Heap
before: https://i.sstatic.net/7eTzm.png
after: https://i.sstatic.net/txeC6.png
converted heap dump file is available upon request
UPDATE
From my debugging, it seems the issue from the LazyList library but I am still not 100% sure. Here is reference to people commenting on the library :
My guess is that you're leaking the activity (which would probably leak all variables it holds). Make sure that any OS call that required you to pass a context have been unregistered, that you don't have any objects that hold a reference to the activity (especially via holding around a context) and that you null out everything you can in onDestroy or onStop (and do so in all your major objects as well).
If that isn't enough, look at your hprof and see what large objects are lieing around after you kill the activity and who's holding the references. Fix and repeat.