java.lang.OutOfMemoryError: bitmap size exceeds VM budget

214 views
Skip to first unread message

shay....@gmail.com

unread,
Aug 14, 2014, 7:32:56 AM8/14/14
to mitappinv...@googlegroups.com
My App PicMyFamily got the attaced ANR on Android 2.3.3 - 2.3.7    device: hsdroid

What does it mean and how to fix it

Thanks

Shay Ben Dov

Crash Report.docx

SteveJG

unread,
Aug 14, 2014, 7:55:39 AM8/14/14
to mitappinv...@googlegroups.com
What the error message probably means is one of your images is too large,  (java.lang.OutOfMemoryError: bitmap size exceeds VM budget)  , here, the bitmap is the image.  

Keep in mind, the images you display in your app should only have a size commiserate with the devices' screen size.   On an average phone this is probably 320 x 480 pixels (though it could be larger and the images probably on the order of 100Kb or so   If you have photos, they easily could be one Mb in size and have dimensions 1000 x 1000.

The solution, use smaller image files.

Of course, I am guessing about the cause of error as I have no information about your app PickMyFamily.

Regards,
Steve

shay....@gmail.com

unread,
Aug 14, 2014, 8:52:13 AM8/14/14
to mitappinv...@googlegroups.com
Steve,

Thanks.

In my app you can either take a picture with phone camera or select one from the pictures stored in the phone various pictures folders.

In the app the image width and height are a percentage of the screen dimension not reaching the limits of the screen.

So I guess the culprit is the file size which I cannot control.

On my Galaxy S4 with Android 4.2.2 I haven't encounter any problems.

I did some digging and found that prior to android 3.0 there were issues with Hardware.Accelarator like:


I hope I got it right.

Can this be the problem and there is a way to control it in AI2.

Thanks Again & Regards,

Shay


SteveJG

unread,
Aug 14, 2014, 9:31:25 AM8/14/14
to mitappinv...@googlegroups.com
Your detective work probably found out what the issue might be.  Yes, file size is the real culprit.  In reality, the Android device can use an photo; even 2 Mb in size, with large dimensions, then it shrinks the image for display.  The image size remains large and this is your issue.

Not knowing whether you display one or two or six photos at the same time, having too many images on display might be the issue or a single large file sized image may be cratering the app.

A simple method would be to discover the size of the image file about to be loaded into your app, if it is greater than a certain size, deny loading but I do not believe there is any way to check the file size using AI2 as there would be in Eclipse or Android Studio.    You might be able to use a 'helper' app if you are a Java guy but that would be considerable work for an accomplished programmer to actually make the images smaller on the fly.

I expect the comments you made will be helpful to others experiencing a similar problem.    I do not have a solution, but someone else might.

Regards,
Steve

Taifun

unread,
Aug 14, 2014, 10:13:44 AM8/14/14
to mitappinv...@googlegroups.com
how many images will be displayed the same time?
how many screens do you have? 
make sure to not have open too much screens the same time, see also this method 
Taifun

shay....@gmail.com

unread,
Aug 14, 2014, 10:25:08 AM8/14/14
to mitappinv...@googlegroups.com
Taifun,

Thanks.

Usually It is 1 Photo and max 1 png image size up 40 KB and 9 average size 15KB

I have 1 screen and 5 canvases each the size of the screen with background image and only 1 is visibile the rest are visible-false.

Thanks Again

Shay

Taifun

unread,
Aug 14, 2014, 10:42:09 AM8/14/14
to mitappinv...@googlegroups.com
I have 1 screen and 5 canvases each the size of the screen with background image and only 1 is visibile the rest are visible-false.

ok, which means, you can have 5 images displayed the same time (1 visible and 4 hidden)
why do you need 5 canvases?
alternatively use different screens instead 
Taifun

shay....@gmail.com

unread,
Aug 14, 2014, 12:18:45 PM8/14/14
to mitappinv...@googlegroups.com
Taifun,

They are different stages of the game.

Every time you see a canvas all the required images for him are fetched and displayed.

So what I need to do is to set the image property of the pictures to none before I declare visible - false and when I move to another canvas bring the required pictures to the image property.

Am I right?

Thanks & Regards,

Shay

Taifun

unread,
Aug 14, 2014, 12:25:47 PM8/14/14
to mitappinv...@googlegroups.com
probably yes, just try it ...
Taifun
Reply all
Reply to author
Forward
0 new messages