0

Having a OOM error with Bitmap factory for my android devices.

Out of memory on a 12582928-byte allocation.

which is weird to me. It is very large. THe files themselves, are images tank on the tablet and downloaded. So the images might reach a 1.2meg jpg or so at the upper bounds.

After it says that Error, it spits out the AndroidRuntime error log for a fatal exception:

10-01 11:53:52.512: E/AndroidRuntime(31023): FATAL EXCEPTION: Thread-7893
10-01 11:53:52.512: E/AndroidRuntime(31023): java.lang.OutOfMemoryError
10-01 11:53:52.512: E/AndroidRuntime(31023):    at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
10-01 11:53:52.512: E/AndroidRuntime(31023):    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:582)
10-01 11:53:52.512: E/AndroidRuntime(31023):    at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:380)
10-01 11:53:52.512: E/AndroidRuntime(31023):    at com.bentley.cordova.plugins.ImageOps.createThumbnailForPath(ImageOps.java:43)
10-01 11:53:52.512: E/AndroidRuntime(31023):    at com.bentley.cordova.plugins.ImageOps.execute(ImageOps.java:20)
10-01 11:53:52.512: E/AndroidRuntime(31023):    at org.apache.cordova.api.PluginManager$1.run(PluginManager.java:192)
10-01 11:53:52.512: E/AndroidRuntime(31023):    at java.lang.Thread.run(Thread.java:856)

I Do have a lot of images processing with this function simultaneously. I didnt think the BitMapFactory was being overworked at all from the different threads running.

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
Fallenreaper
  • 10,222
  • 12
  • 66
  • 129
  • try the bellow links http://stackoverflow.com/questions/1586685/outofmemoryerror-bitmap-size-exceeds-vm-budget-android OR http://stackoverflow.com/questions/1949066/java-lang-outofmemoryerror-bitmap-size-exceeds-vm-budget-android – bashu Oct 01 '12 at 16:17
  • Try this http://stackoverflow.com/questions/477572/android-strange-out-of-memory-issue-while-loading-an-image-to-a-bitmap-object – Mukul Goel Oct 01 '12 at 16:19
  • Keep in mind that a fully expanded image occupies a lot more storage than the stored form in a file. – Hot Licks Oct 01 '12 at 16:19
  • Probably gonna need to see some code, don't even know what you're doing. But have you checked for recursion? Are you releasing your resources when they're done? – Sinaesthetic Oct 01 '12 at 16:19
  • JPEG is compressed, bitmap isn't. With the alpha channel on, every pixel requires 4 bytes to store it. That translates to 3145732 bytes for the pixel matrix or roughly to 1800x1800px; if you're trying to process HD images this is why it fails. Can you look into the dimensions you are trying to create? – Shark Oct 01 '12 at 16:20
  • what is the actual size of the image ? – njzk2 Oct 01 '12 at 16:37
  • I wrote an answer with a couple of hints in a similar issue in this [question](http://stackoverflow.com/questions/12662769/maximum-size-for-android-application/12663152#12663152). Have a look at it and let me know if you need more details. good luck. – Luis Oct 01 '12 at 17:00
  • @Shark I was looking at it, and the fact that images now adays on tablets and other mobile devices are common to be HD, and most liekly causing the data crash. Threading seems to possibly be a cause but it looked like someone was taking a nieve approach to sampling and saving a thumbnail version of it for viewing. I figure, since i know the dimensions i need, with a bit of elbow grease and BitmapFactory.Options, i can get it working. – Fallenreaper Oct 01 '12 at 18:37

2 Answers2

3

So the images might reach a 1.2meg jpg or so at the upper bounds.

that's not true. A 32bit bitmap will require width * height * 4 bytes in order to be allocated. Remember to recycle your bitmap when you do not need it. Also downsample it, if you can

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
  • I was recycle()ing at the end of the bitmap, but it seemed that it wasnt quite downsampling, and after you mentioned it, I looked into it more, as well as the required data for it. It seems that what was trying to be done was a nieve approach of downsizing, which was not ineffecient and was NOT using the Bitmap.Options available to them. – Fallenreaper Oct 01 '12 at 18:34
1

Please consider the fact that a bitmap representation of a 1.2 MB JPEG image may easily (depending on its compression rate) exceed 12 MB.

When using 32bit color a bitmap takes at least width * height * 4 bytes to represent.

Even if a single instance does not exceed the 12MB mark, running this in a threaded manner may exceed the JVM's allocated max heap size.

Tim Lamballais
  • 1,056
  • 5
  • 10
  • The threading might be a big thing with it. As a bunch of images could get pretty large. I am thinking that with the fact that the images arent really downsampled, might be leading to issues. – Fallenreaper Oct 01 '12 at 18:32