views:

109

answers:

1

Hey I seem to be having some kind of memory leak issue with my listview. The list view activity is in a tab and each row downloads an image and displays it in an ImageView (tiling it as a backgroiund). I am using a cache similar to droidfu http://github.com/kaeppler/droid-fu/blob/master/src/main/java/com/github/droidfu/imageloader/ImageCache.java

Everything seems to work fine as I'm completely clearing the memory cache when it gets past 20 items and also completely clearing the disk cache when it gets past 0.5mb just to be safe. The problem occurs when I have a large list of items in the list (say 100) and I keep scrolling back and forth this list as fast as I can. Eventually I get these messages in Logcat:

Heap Massage needed (59892-byte external allocation too big)

Full GC (don't collect SoftReferences)

Clamp target GC heap from 16.277MB to 16.000MB

Try and trim Heap Source

Full GC (collect SoftReferences)

And a whole bunch of those which lead to a force close. I'm not too sure what the problem is or how to go about fixing it :S

Thanks!

Here is the full log: http://pastebin.com/MghMdbxS

Turns out its the problem is with too many AsyncTask/Thread objects being created. I am using the code from http://code.google.com/p/android-imagedownloader/ and not sure how to get this fixed...

A: 

A good place to start is:

http://kohlerm.blogspot.com/2009/04/analyzing-memory-usage-off-your-android.html

It's a little complex to get a dump, but will give you a nice point-of-time static analysis. You will need the Eclipse memory analysis tool (MAT) also:

http://www.eclipse.org/mat/

Good luck!

Nate
thanks! had a quick look..will have a go at it when i get the time.
Kman
Alrighty looks like there are too many AsyncTask objects being created...67 instances infact looking at the report created by MAT. I am using the code from here http://code.google.com/p/android-imagedownloader/ to do the image downloading with AsyncTasks. How do I restrict it so that only a certain amount of AsyncTasks can be instantiated or something like that?
Kman
This goes beyond the original question of "where is my memory leak", but consider using a thread pool instead of instantiating many AsyncTasks
Nate
Sorry, stupid return key ;) http://download.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/ThreadPoolExecutor.html
Nate