[Resolved] Out of Memory crash on lower end android devices

I have a game out on the Android market and it was just brought to my attention that on some devices(which I think are lower end ones) the game crashes whenever it tries to load a level. Checking my logs it looks like it is running into an Out Of Memory error when it’s trying to load spritesheet data via LevelHelper. My initial thought is maybe I am trying to load too many graphics but really I have less than 10mb of graphics in the entire game.

Anyone have any ideas/suggestions? Below is from the logcat on a cheapy device I have. I honestly don’t know how to read it :X

E/dalvikvm-heap( 984): Out of memory on a 15486928-byte allocation. I/dalvikvm( 984): "GLThread 12" prio=5 tid=11 RUNNABLE I/dalvikvm( 984): | group="main" sCount=0 dsCount=0 obj=0x40563570 self=0x344c08 I/dalvikvm( 984): | sysTid=994 nice=0 sched=0/0 cgrp=default handle=3427168 I/dalvikvm( 984): | schedstat=( 5475158658 1336517347 5957 ) I/dalvikvm( 984): at com.ansca.corona.NativeToJavaBridge.getBitmapAsset(NativeToJavaBridge.java:~817) I/dalvikvm( 984): at com.ansca.corona.NativeToJavaBridge.callGetBitmapAsset(NativeToJavaBridge.java:1061) I/dalvikvm( 984): at com.ansca.corona.JavaToNativeShim.nativeTouchEvent(Native Method) I/dalvikvm( 984): at com.ansca.corona.JavaToNativeShim.touchEvent(JavaToNativeShim.java:191) I/dalvikvm( 984): at com.ansca.corona.events.TouchEvent.Send(TouchEvent.java:17) I/dalvikvm( 984): at com.ansca.corona.events.EventManager.sendEvents(EventManager.java:274) I/dalvikvm( 984): at com.ansca.corona.Controller.onDrawFrame(Controller.java:237) I/dalvikvm( 984): at com.ansca.corona.CoronaRenderer.onDrawFrame(CoronaRenderer.java:74) I/dalvikvm( 984): at android.opengl.derived.SwapGLSurfaceView$GLThread.guardedRun(SwapGLSurfaceView.java:968) I/dalvikvm( 984): at android.opengl.derived.SwapGLSurfaceView$GLThread.run(SwapGLSurfaceView.java:825) I/dalvikvm( 984): E/dalvikvm( 984): Out of memory: Heap Size=20039KB, Allocated=3304KB, Bitmap Size=0KB, Limit=32768KB E/dalvikvm( 984): Extra info: Footprint=20039KB, Allowed Footprint=20039KB, Trimmed=652KB [import]uid: 147305 topic_id: 31108 reply_id: 331108[/import]

As an update, I built this on an alternate PC using .840 on Windows(i never use this system which is why it’s on an old release) and it works fine. I am on at .914 my main machine, which is a Mac. Will play around with using various daily builds this evening I guess. [import]uid: 147305 topic_id: 31108 reply_id: 124379[/import]

Well, after a bunch of troubleshooting I found a solution. If I cache my spritesheets when my app loads it takes care of the issue. I really don’t understand why this fixes it but it does.

I managed to find out in the old versions i wouldn’t receive an error but my images from a particular spritesheet would just be white blocks instead of actual images(white blocks might have been background?). On the latest version you actually get the errors. [import]uid: 147305 topic_id: 31108 reply_id: 124460[/import]

As an update, I built this on an alternate PC using .840 on Windows(i never use this system which is why it’s on an old release) and it works fine. I am on at .914 my main machine, which is a Mac. Will play around with using various daily builds this evening I guess. [import]uid: 147305 topic_id: 31108 reply_id: 124379[/import]

Well, after a bunch of troubleshooting I found a solution. If I cache my spritesheets when my app loads it takes care of the issue. I really don’t understand why this fixes it but it does.

I managed to find out in the old versions i wouldn’t receive an error but my images from a particular spritesheet would just be white blocks instead of actual images(white blocks might have been background?). On the latest version you actually get the errors. [import]uid: 147305 topic_id: 31108 reply_id: 124460[/import]

Hi budershank,

I am facing exactly the same issue on some Android devices.
Would you be so kind and let me know how you cache your sprites when loading levels please?

Thanks
[import]uid: 145610 topic_id: 31108 reply_id: 127566[/import]

Well, I actually cached all my sprites before the loading level process even started. This means they are taking up memory all the time(which in my case was acceptable).

Basically all you do is load the image off-screen and leave it there. It’s as simple as

[lua]local myCachedImage = display.newImageRect(“myspritesheet.png”, 100, 100)
myCachedImage.x = 1000000
myCachedImage.y = 1000000[/lua]

Hope that makes sense, haven’t had coffee yet. [import]uid: 147305 topic_id: 31108 reply_id: 127573[/import]

Thank you very much,

appreciate your fast response.

I will try that

Regards
[import]uid: 145610 topic_id: 31108 reply_id: 127574[/import]

Hi budershank,

I am facing exactly the same issue on some Android devices.
Would you be so kind and let me know how you cache your sprites when loading levels please?

Thanks
[import]uid: 145610 topic_id: 31108 reply_id: 127566[/import]

Well, I actually cached all my sprites before the loading level process even started. This means they are taking up memory all the time(which in my case was acceptable).

Basically all you do is load the image off-screen and leave it there. It’s as simple as

[lua]local myCachedImage = display.newImageRect(“myspritesheet.png”, 100, 100)
myCachedImage.x = 1000000
myCachedImage.y = 1000000[/lua]

Hope that makes sense, haven’t had coffee yet. [import]uid: 147305 topic_id: 31108 reply_id: 127573[/import]

Thank you very much,

appreciate your fast response.

I will try that

Regards
[import]uid: 145610 topic_id: 31108 reply_id: 127574[/import]

Hi, I am using your code 

  1. local myCachedImage = display.newImageRect(“myspritesheet.png”, 100, 100)myCachedImage.x = 1000000myCachedImage.y = 1000000

but i get a white screen and the image is not uploaded 

Hi, I am using your code 

  1. local myCachedImage = display.newImageRect(“myspritesheet.png”, 100, 100)myCachedImage.x = 1000000myCachedImage.y = 1000000

but i get a white screen and the image is not uploaded