In my project, i have a simple activity composed of a single XML layout (enabled by setContentView). The project has other activities though.
The layout is basically composed of two .jpg images. The first one has 25kB and is 400×153 px. The second one has 4kB and is 150×50 px.
Despite this very simple context, the DDMS tells me i have 13MB allocated to my program, which i think is huge, given i only have two small images loaded, and that some device have a maximum heap size of 16MB for each program.
Is it normal for the heap to be so big in this layout?
EDIT: HProf Dump:
Problem Suspect 1:
The class “android.content.res.Resources”, loaded by “”, occupies 9,429,232 (70.39%) bytes. The memory is accumulated in one instance of “java.lang.Object[]” loaded by “”.Problem Suspect 2:
3 instances of “android.graphics.Bitmap”, loaded by “” occupy 2,147,960 (16.03%) bytes.
Biggest instances:
•android.graphics.Bitmap @ 0x41407b98 - 1,048,648 (7.83%) bytes.
•android.graphics.Bitmap @ 0x4169e6a0 - 979,256 (7.31%) bytes.
I can’t really interpret this. But it seems like my other resources are being loaded before-hand? (before I enter their respective activities?)
If you say that that’s all your program is trying to do, then it’s normal. Bitmaps do take up a lot of memory. Try to optimize your images, and that should definitely help you in reducing the memory footprint of your apps. Think about 9-patch images while creating backgrounds.