Discussion Forums  >  Crashes, Memory Warnings

Replies: 11    Views: 806

Eric F
Lost but trying
Profile
Posts: 13
Reg: Mar 21, 2013
Clovis
3,380
06/26/13 10:19 AM (10 years ago)

Android App keeps crashing due to exceeded VM budget error

I am trying to create a very basic app using mainly menu screens loaded with background images and call us menu buttons. It is working fine for a few iterations of navigating through the different menu screen then it crashes due to the following errors. (Note: I have read some stuff that says to shrink the image file size to keep from getting these errors and I have I have shrank them 60% down to 340 x 460 size which makes each image when converted to bmp by the app to display is less than 2Mb a piece). I have been wondering but can't figure out if there is a way to clear the VM budget every time you press a button, but don't know if that is the fix either. Any help would be greatly appreciated. log cat: 06-26 16:58:43.869: E/AndroidRuntime(325): FATAL EXCEPTION: main 06-26 16:58:43.869: E/AndroidRuntime(325): java.lang.OutOfMemoryError: bitmap size exceeds VM budget 06-26 16:58:43.869: E/AndroidRuntime(325): at android.graphics.Bitmap.nativeCreate(Native Method) 06-26 16:58:43.869: E/AndroidRuntime(325): at android.graphics.Bitmap.createBitmap(Bitmap.java:468) 06-26 16:58:43.869: E/AndroidRuntime(325): at android.graphics.Bitmap.createBitmap(Bitmap.java:435) 06-26 16:58:43.869: E/AndroidRuntime(325): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340) 06-26 16:58:43.869: E/AndroidRuntime(325): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488) 06-26 16:58:43.869: E/AndroidRuntime(325): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:462) 06-26 16:58:43.869: E/AndroidRuntime(325): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323) 06-26 16:58:43.869: E/AndroidRuntime(325): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697) 06-26 16:58:43.869: E/AndroidRuntime(325): at android.content.res.Resources.loadDrawable(Resources.java:1709) 06-26 16:58:43.869: E/AndroidRuntime(325): at android.content.res.Resources.getDrawable(Resources.java:581) 06-26 16:58:43.869: E/AndroidRuntime(325): at com.quickreaction.BT_fileManager.getDrawableByName(BT_fileManager.java:263) 06-26 16:58:43.869: E/AndroidRuntime(325): at com.quickreaction.BT_screen_menuButtons.getButton(BT_screen_menuButtons.java:771) 06-26 16:58:43.869: E/AndroidRuntime(325): at com.quickreaction.BT_screen_menuButtons.layoutButtons(BT_screen_menuButtons.java:624) 06-26 16:58:43.869: E/AndroidRuntime(325): at com.quickreaction.BT_screen_menuButtons.parseScreenData(BT_screen_menuButtons.java:944) 06-26 16:58:43.869: E/AndroidRuntime(325): at com.quickreaction.BT_screen_menuButtons.onStart(BT_screen_menuButtons.java:238) 06-26 16:58:43.869: E/AndroidRuntime(325): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129) 06-26 16:58:43.869: E/AndroidRuntime(325): at android.app.Activity.performStart(Activity.java:3781) 06-26 16:58:43.869: E/AndroidRuntime(325): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2636) 06-26 16:58:43.869: E/AndroidRuntime(325): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 06-26 16:58:43.869: E/AndroidRuntime(325): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 06-26 16:58:43.869: E/AndroidRuntime(325): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 06-26 16:58:43.869: E/AndroidRuntime(325): at android.os.Handler.dispatchMessage(Handler.java:99) 06-26 16:58:43.869: E/AndroidRuntime(325): at android.os.Looper.loop(Looper.java:123) 06-26 16:58:43.869: E/AndroidRuntime(325): at android.app.ActivityThread.main(ActivityThread.java:4627) 06-26 16:58:43.869: E/AndroidRuntime(325): at java.lang.reflect.Method.invokeNative(Native Method) 06-26 16:58:43.869: E/AndroidRuntime(325): at java.lang.reflect.Method.invoke(Method.java:521) 06-26 16:58:43.869: E/AndroidRuntime(325): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 06-26 16:58:43.869: E/AndroidRuntime(325): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 06-26 16:58:43.869: E/AndroidRuntime(325): at dalvik.system.NativeStart.main(Native Method)
 
Sandeep
Android Fan
Profile
Posts: 1260
Reg: Feb 01, 2012
Miraj, India
25,250
like
06/26/13 10:54 AM (10 years ago)
The best option is to reduce the size of the images. But there is another way to solve this problem. Instead of using all those image files locally (including those images in the app), you can put those images on your server or dropbox and refer the url instead. This will solve your problem.
 
Paul Rogers
Android Fan
Profile
Posts: 2524
Reg: May 30, 2011
UK
35,740
like
06/26/13 11:26 AM (10 years ago)
@Eric F, from your post it sounds like you're reducing the dimension sizes of your images? You should try to reduce the actual mb file size. If you have png images try running them through http://tinypng.org/ If you have jpg's run them through Yahoo's smushit: http://www.smushit.com/ysmush.it/ You'd be best off using flattened 8bit png's too, if possible. Depending on the subject matter you could also try reducing the amount of colours from 256 to 128, there shouldn't be a big difference in quality unless you're using high resolutions. 2mb is a huge size for Android, it doesn't handle images well at all, ideally you should try and get them down to, at most, around 100kb. Or as @Sandeep says, host them online, but then you'd be relying on the user having an internet connection.
 
Eric F
Lost but trying
Profile
Posts: 13
Reg: Mar 21, 2013
Clovis
3,380
like
06/26/13 10:13 PM (10 years ago)
Thanks guys for posting back so fast. Posting online is not an option for this app as it has to be available when internet would not be available. I did try tinypng and it has compressed all my image files down to 55 kb or less except for one file that is 103 kb. I am still running into the same problem with VM running out of room. To give a little more detail on the project. The menu button screens use a background image to display some picture but mainly text images. The buttons I have displayed on the bottom of the screen and they are image files as well. Most range from 2 to 3 kb. so the most that would ever be loaded on at one screen application would be about 150 kb and that would be the main screen with all the rest being closer to the 70 kb or less of images being loaded. I have included the log cat again on this last attempt. Thanks again for the help. 06-27 05:03:00.439: E/dalvikvm-heap(357): 141376-byte external allocation too large for this process. 06-27 05:03:00.439: E/GraphicsJNI(357): VM won't let us allocate 141376 bytes 06-27 05:03:00.439: D/AndroidRuntime(357): Shutting down VM 06-27 05:03:00.496: W/dalvikvm(357): threadid=1: thread exiting with uncaught exception (group=0x4001d800) 06-27 05:03:00.539: E/AndroidRuntime(357): FATAL EXCEPTION: main 06-27 05:03:00.539: E/AndroidRuntime(357): java.lang.OutOfMemoryError: bitmap size exceeds VM budget 06-27 05:03:00.539: E/AndroidRuntime(357): at android.graphics.Bitmap.nativeCreate(Native Method) 06-27 05:03:00.539: E/AndroidRuntime(357): at android.graphics.Bitmap.createBitmap(Bitmap.java:468) 06-27 05:03:00.539: E/AndroidRuntime(357): at com.quickreaction.BT_viewUtilities.getRoundedImage(BT_viewUtilities.java:392) 06-27 05:03:00.539: E/AndroidRuntime(357): at com.quickreaction.BT_screen_menuButtons.getButton(BT_screen_menuButtons.java:775) 06-27 05:03:00.539: E/AndroidRuntime(357): at com.quickreaction.BT_screen_menuButtons.layoutButtons(BT_screen_menuButtons.java:624) 06-27 05:03:00.539: E/AndroidRuntime(357): at com.quickreaction.BT_screen_menuButtons.parseScreenData(BT_screen_menuButtons.java:944) 06-27 05:03:00.539: E/AndroidRuntime(357): at com.quickreaction.BT_screen_menuButtons.onStart(BT_screen_menuButtons.java:238) 06-27 05:03:00.539: E/AndroidRuntime(357): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129) 06-27 05:03:00.539: E/AndroidRuntime(357): at android.app.Activity.performStart(Activity.java:3781) 06-27 05:03:00.539: E/AndroidRuntime(357): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2636) 06-27 05:03:00.539: E/AndroidRuntime(357): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 06-27 05:03:00.539: E/AndroidRuntime(357): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 06-27 05:03:00.539: E/AndroidRuntime(357): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 06-27 05:03:00.539: E/AndroidRuntime(357): at android.os.Handler.dispatchMessage(Handler.java:99) 06-27 05:03:00.539: E/AndroidRuntime(357): at android.os.Looper.loop(Looper.java:123) 06-27 05:03:00.539: E/AndroidRuntime(357): at android.app.ActivityThread.main(ActivityThread.java:4627) 06-27 05:03:00.539: E/AndroidRuntime(357): at java.lang.reflect.Method.invokeNative(Native Method) 06-27 05:03:00.539: E/AndroidRuntime(357): at java.lang.reflect.Method.invoke(Method.java:521) 06-27 05:03:00.539: E/AndroidRuntime(357): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 06-27 05:03:00.539: E/AndroidRuntime(357): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 06-27 05:03:00.539: E/AndroidRuntime(357): at dalvik.system.NativeStart.main(Native Method)
 
Paul Rogers
Android Fan
Profile
Posts: 2524
Reg: May 30, 2011
UK
35,740
like
06/27/13 04:20 AM (10 years ago)
Hi @Eric F, are you using an emulator that you've set up in the AVD or using a real device as an emulator? It looks like there's only a tiny amount of virtual memory allocated, less than 140kb. If it's an emulator you've set up, go into the avd manager, edit the emulator you've set up and increase the "Max VM application heap size" in the "Hardware" section. I think, in an emulator, it should be set to 16mb or maybe more. If you're using a phone, is it old and full of running processes?!
 
Eric F
Lost but trying
Profile
Posts: 13
Reg: Mar 21, 2013
Clovis
3,380
like
06/27/13 05:28 AM (10 years ago)
It crashes on both the emulator and a real device. The device that I have been using the most is my wife's nexus 7 which we just purchased about three months ago. I am sure there are plenty of running processes on the device. I have been ready other blogs with memory crashes and they have been talking about a garbage collector and running it at the beginning of the picture heavy processes. How would I add this and would this help? Thanks again.
 
Paul Rogers
Android Fan
Profile
Posts: 2524
Reg: May 30, 2011
UK
35,740
like
06/27/13 06:30 AM (10 years ago)
@Eric F - What you'd do is finish each activity to free it up for Garbage Collection, so, for example, on a button click that opens a new activity (screen), the last line of code would be "this.finish();". The thing is, from what you've described, the app isn't particularly image heavy, there could be other reasons for this, like a memory leak somewhere. For the purposes of troubleshooting could you test with some tiny images, like 1kb? Have you added/modified any code? If so, try and backtrack each step you've done. And test at each stage. If you haven't done too much work, it may even help to redownload the project and start again. A very technical way of finding out what's going on is to make sure 'debuggable' is set to true in the manifest, open the DDMS perspective in eclipse, run the app in the emulator and dump an HPROF file for analysis. Would require a pdf guide for this!, but with the help of google/stackoverflow, you'd need to dump the HPROF file, convert it from Dalvik to Java and use memory analiser software to interpret the results. It'll show you what's causing the issues, but then you'd need to find out how to fix them. This is overkill though and a last resort! You could send over the project if you like? Another set of eyes and all that.. email is paul9qr @ btinternet dot com
 
Eric F
Lost but trying
Profile
Posts: 13
Reg: Mar 21, 2013
Clovis
3,380
like
06/27/13 07:48 AM (10 years ago)
@raveyd - I haven't touch the code manually yet, so I don't think that is the problem. I will redownload from buzztouch and rerun the program and see if that takes care of it. If not I will send it your way for another set of eyes. I really apprecaite all the help. Be looking for an email from uglyfool11 @ yahoo com when I do send.
 
Paul Rogers
Android Fan
Profile
Posts: 2524
Reg: May 30, 2011
UK
35,740
like
06/27/13 08:02 AM (10 years ago)
Ok Eric, good luck! Sometimes just a redownload can fix things, hope it's the case here. I'm sure one way or another we can get the app running ok.
 
Eric F
Lost but trying
Profile
Posts: 13
Reg: Mar 21, 2013
Clovis
3,380
like
06/27/13 12:53 PM (10 years ago)
@raveyd - just sent the apk file your way to take a look at. I really appreciate the help.
 
Paul Rogers
Android Fan
Profile
Posts: 2524
Reg: May 30, 2011
UK
35,740
like
06/27/13 03:25 PM (10 years ago)
It force closes on my htc one x too. Could you send your project over, not the apk? I could run it through DDMS, see where the errors are occuring in the code.
 
Eric F
Lost but trying
Profile
Posts: 13
Reg: Mar 21, 2013
Clovis
3,380
like
06/27/13 03:58 PM (10 years ago)
Definitely, can. I will send it over in a minute.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.