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: http://i.stack.imgur.com/7eTzm.png
after: http://i.stack.imgur.com/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 :
https://github.com/thest1/LazyList/issues/20
To find out which apps are using your memory, you must first enable the Developer options. To do that, open the Settings app and then tap About Phone. Scroll to the bottom of that window and then tap Build number 7 times. After the seventh tap, you'll be informed that the Developer options has been enabled.
Memory leaks occur when an application allocates memory for an object, but then fails to release the memory when the object is no longer being used. Over time, leaked memory accumulates and results in poor app performance and even crashes.
Android's memory heap is a generational one, meaning that there are different buckets of allocations that it tracks, based on the expected life and size of an object being allocated. For example, recently allocated objects belong in the Young generation.
The Memory Profiler is a component in the Android Profiler that helps you identify memory leaks and memory churn that can lead to stutter, freezes, and even app crashes. It shows a realtime graph of your app's memory use and lets you capture a heap dump, force garbage collections, and track memory allocations.
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.
It sounds to me like you are starting a new activity each time, rather than switching to the one already loaded. Try setting the flags on the intent to include Intent.FLAG_ACTIVITY_REORDER_TO_FRONT when you switch activities.
See this
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With