My android app leaks, what should I check?
I gave a look at avoiding memory leaks and I added some unbindDrawables() calls in the onDestroy() methods of the activities to clean up but nothing changed. I also replace every getContext() calls by getApplicationContext() but nothing changed either.
I monitor the heap size in the DDMS eclipse perspective : when I launch the app for the first time there 3Mb allocated and after 10 close/restart it there’s 10Mb allocated.
My views are mainly composed of ViewFlippers and many nested Layouts that inherit from a subclass of LinearLayout.
EDIT:
after running MAT to identify leak suspects the main problem is :
16 instances of "org.apache.http.impl.conn.tsccm.ConnPoolByRoute",
loaded by "<system class loader>" occupy 4,000,328 (44.08%) bytes.
If you’re using
getApplicationContext()all over the place then for sure you are leaking memory! That’s generally a bad idea. You need to use the proper context in the proper place.Take a heap dump, use a profiler (like MAT or jhat) and look at the instances that shouldn’t be there (activities that should have been destroyed). Follow the chain of references back and figure out why they aren’t getting reclaimed.