开发者

RGB_565 bitmap in Android - how much does it take in memory?

How much memory does RGB_565 bitmap occupy in Android? I would guess 2 bytes per pixel but:

  1. I have 256x256 bitmaps, so 1 would have 256 * 256 * 2 = 131,072 bytes
  2. My app (offline tiled map) throws OutOfMemoryError on N1 (2.3) when 143 bitmaps are in memory. 143 开发者_如何学JAVAbitmaps is 18MB. Max heap size on my phone is 32 MB.
  3. That would imply that the rest of my app is 32 - 18 = 14 MB. But i see only a little over 7 MB in DDMS > Heap. Also, I would have only 2 MB for bitmaps on 16 MB heap size devices.


On nexus one each android app is limited to 24MB of memory this includes any bitmaps that you allocate.

It also adds up - your app without bitmaps is taking around 7MB and when you allocate for 143 bitmaps I think you are breaching the 24MB limit thus causing the exception.

Discussed in more detail in this post here


In Android < 3.0, bitmaps does not occupy space in Dalvik heap, instead they are stored in the native heap. You can't see how much memory the bitmaps have taken in the DDMS Heap (btw, you can, you should put something like "native=true" in the ddms config file).

In 3.0+, bitmap data is stored in the Dalvik heap.

If you have other images (also backgrounds in xml files, images in xml) they have taken up the other space. I've had a lot of OutOfMemoryIssues because I used too large images as backgrounds.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜