tags:

views:

756

answers:

2

Hi

I am working on an application for android and we since we have lots of graphics, we use a lot of memory.

I monitor the memory heap size and its about 3-4 Mb , and peeks of 5Mb when I do something that requires more memory (and then goes back to 3). This is not a big deal, but some other stuff is handled outside the heap memory, like loading of drawables.

For example if I run the ddms tool outside eclipse, and go to sysinfo, I see that my app is taking 20Mb on the Droid and 12 on the G1, but heap size are the same in both, because data is the same but images are different.

So the questions are: How do I know what is taking the memory outside the heap memory? What other stuff takes memory outside the heap memory? Complex layouts (big tree) ? Animations?

Thanks

Daniel

+1  A: 

One obvious candidate is off course off-screen bitmaps (double-buffering by android?), since the screensize has ~4x as many pixels on the droid.

sandos
thanks, I am looking for a way to track the memory outside the heap.
Daniel Benedykt
+2  A: 

Bitmap objects takes a quite alot of memory.

Ex. if your app downloads a 10KB jpg from net and use BitmapFactory to decode it into a Bitmap that bitmap objects needs about 30-100KB memory, depending on the resolution of your image. 3bytes for each pixel (1 byte for each color)

And yes, all kind of object uses memory, like LinearLayouts, ImageViews etc... If you are creating and destroying many of these objects, ex. as you scroll / page through your images, there will be memory leaks. The gc() does not handle so-called short lived objects as fast as we would like.

Keep the number of view objects at a stable level*, and recycle them instead of destroying and creating new ones.

REf: http://developer.android.com/resources/articles/track-mem.html

If your app reaches 20MB in memory, it may FC as the BitmapFactory is trying to decode the next image.

PHP_Jedi