views:

232

answers:

1

I have created an hprof file by inserting the statement Debug.dumpHprofData("/sdcard/myapp.hprof"); in my app's code; I have then run the hprof file through hprof-conv and opened the converted file in Eclipse.

Following the advice of the MAT "Cheat Sheet" I have obtained an analysis of my app's memory usage by going to "Leak Identification -> Component Report" entering "com.prepbgg.*" and hitting Finish.

I know that my app is consuming large amounts of memory: in particular at the stage where I called dumpHprofData it had a one megapixel bitmap object and a canvas that must have consumes several hundred KB. (I also suspect that it is leaking significant amounts of memory because performance degrades severely after the screen has been rotated a few times.)

However, the Component Report for com.prepbgg.* shows total memory of only 38.7KB. The Histogram view shows for android.graphics.Bitmap (presumably this is the total of all apps including mine) 404 objects and Shallow Heap 12,928. Is that 12,928 bytes?

Clearly, my app consumes more than 38.7KB and the Bitmap far more than 12,928 bytes. Where am I going wrong? How can I see the total memory consumed by my app?

+1  A: 

most of the space for the bitmap will be on the native heap. see the source for Bitmap: it has seven fields. assume each field is four bytes (almost certain for the reference and ints, and plausible for the booleans) add an extra four bytes for the object header, and:

(7*4 + 4) * 404 = 12928

i don't think there's any easy way to examine the native heap without running your own build yet.

you can ask how much stuff's been allocated: http://developer.android.com/reference/android/os/Debug.html#getNativeHeapAllocatedSize()

Elliott Hughes
Thanks very much for your helpful answer, Elliott. Does getNativeHeapAllocatedSize show the total memory used by my app which is not included in the total (38.7KB) shown in the Component Report for my com.prepbgg.* namespace? (As well as the BitMap the obvious large objects that my app uses are the Canvas and a SQLite database of nearly 300KB. Will these also be in the Native Heap?)