17.8. Placing a MiB heap for a simple Hello World project?

I assume there is an obvious answer here ... I am left at a loss with this:

Why am I getting a 17.8 heap of MiB memory allocated when all I did is:

  • Created a simple Hello World project with the Eclipse New Project parameter.
  • And added a background image of 56 KiB.

If I post the line android:background="@drawable/background4" , the allocated memory drops to 11.9 MiB.

  • Is it normal if the system allocates so much memory? Should I worry about this?
  • What will this large part of the heap take?

I also ran a MAT report, but I'm not sure which conclusion to draw from it:

Thanks in advance,

+6
source share
3 answers

And added a background image of 56 KiB.

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

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

+4
source

AFAIK Android converts the image in your layout into a byte array when it inflates your layout.

This requires a background image to fit into your screen, and this requires additional memory. Therefore, he allocates so much memory. I may not be right, but let me know if I am wrong.

+1
source

Well, I could be wrong by the number here, but something above Android 3 will have a 24 MB limit (up to 16 MB before that and varies from device to device) for the heap of memory. And, as is the case with each JVM, the memory will be allocated almost completely, so your application will not need to perform redistribution during the life cycle.

Not to say that your application actually runs on 24 MB, but it stands out if it needs it.

I know that you can also increase the amount of heap memory that your application can use, but I suggest revising your code if you feel the need to do this.

Obviously, everything that gets garbage will be collected as soon as your application is closed.

Update Here, how would you increase the heap if necessary:

 android:largeHeap="true" 
0
source

All Articles