Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

17.8 MiB heap allocation for a simple "Hello World" project?

I am guessing there is an obvious answer here... I am left confused with this one:

Why do I get 17.8 MiB heap memory allocated when all I have done is:

  1. Created a simple "Hello World" project with Eclipse's New Project option.
  2. And added a 56 KiB background image.

If I take out the android:background="@drawable/background4" line, the allocated memory goes down to 11.9 MiB.

  • Is this normal for the system to allocate this much memory? Should I worry about it?
  • What would take up this much of the heap?

I also ran a MAT report on it, but I am not sure what conclusion to draw from it:

Thanks in advance,

like image 886
Crocodile Avatar asked Mar 14 '13 08:03

Crocodile


2 Answers

And added a 56 KiB background image.

No, you added a 56 KiB file that you are using as a background image.

The actual heap space consumed by a bitmap is three bytes per pixel. With a ~6MB bitmap (per your MAT screen), you are running your app on a fairly high resolution device or emulator (1080p should result in ~8MB, IIRC).

like image 137
CommonsWare Avatar answered Oct 22 '22 18:10

CommonsWare


AFAIK Android will convert the image in your layout to byte Array when it inflate your layout.

It needs background image to expand to fit into your screen, doing that takes extra memory..so that 's why it allocate that much memory. I may not be right but let me know if I am wrong.

like image 33
Pragnani Avatar answered Oct 22 '22 18:10

Pragnani