0

Possible Duplicate:
Android: Strange out of memory issue

I'm trying to work with four bitmaps of 1024 x 1024, I need to have four in memory because I am creating a gallery that must show four zoomable bitmaps in landscape mode.

It is working on Motorola Droid 2.2.3, but it is failing on galaxy spica (2.1). This is the exception that i get on spica:

02-28 15:45:25.963: ERROR/dalvikvm-heap(17109): 4194304-byte external allocation too large for this process.
02-28 15:45:25.968: ERROR/(17109): VM won't let us allocate 4194304 bytes
02-28 15:45:25.973: DEBUG/AndroidRuntime(17109): Shutting down VM
02-28 15:45:25.973: WARN/dalvikvm(17109): threadid=3: thread exiting with uncaught exception (group=0x4001b180)
02-28 15:45:25.973: ERROR/AndroidRuntime(17109): Uncaught handler: thread main exiting due to uncaught exception
02-28 15:45:25.988: ERROR/AndroidRuntime(17109): java.lang.OutOfMemoryError: bitmap size exceeds VM budget

how to solve this?

thanks

Community
  • 1
  • 1
NullPointerException
  • 36,107
  • 79
  • 222
  • 382

2 Answers2

0

There is no easy way to solve that - single application has very low memory budget, so there is no way to keep 16MB in memory. You can use OpenGL (textures are not included into that budget), of just use one bitmap at time (or use smaller bitmaps).

piotrpo
  • 12,398
  • 7
  • 42
  • 58
  • it is not 16MB, it is 4MB, and yes, i'm using OPENGL and im reciclyng ALL the bitmaps i am using – NullPointerException Feb 28 '12 at 15:06
  • 1024px*1024px*4B*4 bitmaps = 16MB - You just get error trying to allocate one of them. Usually 16MB is total memory budget for single app. OpenGL textures has separate budget. – piotrpo Feb 28 '12 at 16:03
0

You can cut the size in half by using RGB_565 versus the default ARGB_8888.

  • ARGB_8888 requires 4 bytes per pixel: 4*1024*1024 = 4194304 (4mb)

  • RGB_565 require 2 bytes per pixel: 2*1024*1024 = 2097152 (2mb)

You can set this with options to the BitmapFactory. See inPreferredConfig

However even with this you'll still have difficulty. Why not cut the size of the images down as well? I doubt you're able to show a 1024x1024 image anyway.

dbryson
  • 6,047
  • 2
  • 20
  • 20