Domanda

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,

È stato utile?

Soluzione

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).

Altri suggerimenti

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.

Ok, I could be wrong on the number here, but anything above Android 3 will have 24mb (16mb before that and varies from device to device) limit for the memory heap. And as with every JVM, the memory will be allocated almost in full, so your application won't need to do reallocations during its life-cycle.

That's not to say your application is actually running at 24mb, but has this allocated if it needs that.

I know you can also increase the amount of heap memory your application could use, but I'd suggest revisiting your code in case you feel the need to do so.

Obviously all that will get garbage collected as soon as your application is closed.

Update Here's how you would increase the heap if needed:

android:largeHeap="true"
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top