This error message is thrown when the process' memory limit has been
reached.

In other words, there is no hard limit to the size of bitmap that can
be constructed by the system.

Most phones have a 16MByte heap-limit. Phones with larger cameras
(allowing to snap pics with 5 or 8MPix) may have a 24MByte heap-limit.
This means that the absolute upper limit is either 16 or 24MByte.

However, the rest of your app uses memory as well. You have to
subtract that from the 16 or 24MByte.

In my app, i have a hard limit of 8MByte for images. I.e. if an
image's data would be more than 8MByte, i set the inSampleSize to a
value larger than 1. In the mean time, i'm very aggresive in cleaning
up memory in the rest of my app if i'm about to load a large image
(clear caches, especially ones holding bitmaps, calling System.gc()
forcefully, etc).




On Mar 1, 3:00 am, wei yan <yan.wei...@gmail.com> wrote:
> Hi:
> some of you may met the same problem, I was using
> BitmapFactory.decodeStream, and got this exception:
>
> 03-01 23:28:17.663: ERROR/dalvikvm-heap(940): 1572864-byte external
> allocation too large for this process.
> 03-01 23:28:17.663: ERROR/(940): VM won't let us allocate 1572864
> bytes
> 03-01 23:28:17.663: DEBUG/skia(940): --- decoder->decode returned
> false
> 03-01 23:28:17.663: WARN/dalvikvm(940): threadid=27: thread exiting
> with uncaught exception (group=0x4001b188)
> 03-01 23:28:17.663: ERROR/AndroidRuntime(940): Uncaught handler:
> thread Thread-14 exiting due to uncaught exception
> 03-01 23:28:17.663: ERROR/AndroidRuntime(940):
> java.lang.OutOfMemoryError: bitmap size exceeds VM budget
> 03-01 23:28:17.663: ERROR/AndroidRuntime(940):     at
> android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
> 03-01 23:28:17.663: ERROR/AndroidRuntime(940):     at
> android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:459)
> 03-01 23:28:17.663: ERROR/AndroidRuntime(940):     at
> cc.pa.BitmapManager.fetchBitmap(BitmapManager.java:39)
> 03-01 23:28:17.663: ERROR/AndroidRuntime(940):     at
> cc.pa.BitmapManager$2.run(BitmapManager.java:88)
>
> I know the reason is because the BitmapFactory is trying to decode an
> uncompressed version of a big image(in my situation, jpg). I can use
> BitmapFactory.Options.inSampleSize to fix it. but my question is
> what's the maximum size that VM would like to allocate for loading a
> image with BitmapFactory? so I can do some scale before it loads.
>
> thanks
> wei

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to