Out of Memory Error Help

Hello, I’m entering the testing phase and everything works fine on pc, on android I get the following error when trying to load a scene (the j3o is 11.6mb):

E/dalvikvm-heap(29725): Out of memory on a 20963344-byte allocation.
I/dalvikvm(29725): "GLThread 1265" prio=5 tid=11 RUNNABLE
I/dalvikvm(29725):   | group="main" sCount=0 dsCount=0 obj=0x42012008 self=0x41462490
I/dalvikvm(29725):   | sysTid=29740 nice=0 sched=0/0 cgrp=apps handle=1090582904
I/dalvikvm(29725):   | schedstat=( 20872346605 4244910837 27070 ) utm=1979 stm=107 core=1
I/dalvikvm(29725):   at java.io.ByteArrayOutputStream.expand(ByteArrayOutputStream.java:~91)
I/dalvikvm(29725):   at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:201)
I/dalvikvm(29725):   at com.jme3.export.binary.BinaryImporter.load(BinaryImporter.java:234)
I/dalvikvm(29725):   at com.jme3.export.binary.BinaryImporter.load(BinaryImporter.java:125)
I/dalvikvm(29725):   at com.jme3.export.binary.BinaryImporter.load(BinaryImporter.java:109)
I/dalvikvm(29725):   at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:288)
I/dalvikvm(29725):   at com.jme3.asset.DesktopAssetManager.loadModel(DesktopAssetManager.java:374)
I/dalvikvm(29725):   at com.jme3.asset.DesktopAssetManager.loadModel(DesktopAssetManager.java:378)
I/dalvikvm(29725):   at Kart_Mart.GameplayState.initialize(GameplayState.java:163)
I/dalvikvm(29725):   at com.jme3.app.state.AppStateManager.initializePending(AppStateManager.java:251)
I/dalvikvm(29725):   at com.jme3.app.state.AppStateManager.update(AppStateManager.java:281)
I/dalvikvm(29725):   at com.jme3.app.SimpleApplication.update(SimpleApplication.java:239)
I/dalvikvm(29725):   at com.jme3.app.AndroidHarness.update(AndroidHarness.java:467)
I/dalvikvm(29725):   at com.jme3.system.android.OGLESContext.onDrawFrame(OGLESContext.java:349)
I/dalvikvm(29725):   at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1516)
I/dalvikvm(29725):   at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
W/dalvikvm(29725): threadid=11: thread exiting with uncaught exception (group=0x4156e2a0)
E/com.jme3.app.AndroidHarness(29725): SEVERE Exception thrown in Thread[GLThread 1265,5,main]
E/com.jme3.app.AndroidHarness(29725): java.lang.OutOfMemoryError
E/com.jme3.app.AndroidHarness(29725): 	at java.io.ByteArrayOutputStream.expand(ByteArrayOutputStream.java:91)
E/com.jme3.app.AndroidHarness(29725): 	at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:201)
E/com.jme3.app.AndroidHarness(29725): 	at com.jme3.export.binary.BinaryImporter.load(BinaryImporter.java:234)
E/com.jme3.app.AndroidHarness(29725): 	at com.jme3.export.binary.BinaryImporter.load(BinaryImporter.java:125)
E/com.jme3.app.AndroidHarness(29725): 	at com.jme3.export.binary.BinaryImporter.load(BinaryImporter.java:109)
E/com.jme3.app.AndroidHarness(29725): 	at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:288)
E/com.jme3.app.AndroidHarness(29725): 	at com.jme3.asset.DesktopAssetManager.loadModel(DesktopAssetManager.java:374)
E/com.jme3.app.AndroidHarness(29725): 	at com.jme3.asset.DesktopAssetManager.loadModel(DesktopAssetManager.java:378)
E/com.jme3.app.AndroidHarness(29725): 	at Kart_Mart.GameplayState.initialize(GameplayState.java:163)
E/com.jme3.app.AndroidHarness(29725): 	at com.jme3.app.state.AppStateManager.initializePending(AppStateManager.java:251)
E/com.jme3.app.AndroidHarness(29725): 	at com.jme3.app.state.AppStateManager.update(AppStateManager.java:281)
E/com.jme3.app.AndroidHarness(29725): 	at com.jme3.app.SimpleApplication.update(SimpleApplication.java:239)
E/com.jme3.app.AndroidHarness(29725): 	at com.jme3.app.AndroidHarness.update(AndroidHarness.java:467)
E/com.jme3.app.AndroidHarness(29725): 	at com.jme3.system.android.OGLESContext.onDrawFrame(OGLESContext.java:349)
E/com.jme3.app.AndroidHarness(29725): 	at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1516)
E/com.jme3.app.AndroidHarness(29725): 	at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)

Any links to threads that would help solve this problem are greatly appreciated. Thanks for your time.

Depending on the device, you may have a heap size of 16mb for your process, 32 if your lucky. 24 or 48 if you add android:largeHeap=“true” in your manifest. Some more recent device may have more…but you can’t bet on the device your users will use.
A 11.6Mb model is just too large for android platforms.
I guess your only choise is to put it on a diet.

I read more about the issue and actually since android 3, heap size works differently.(still depends of the vendor though)
You have a minimum heap size (generaly pretty low like 8 or 16 mb).
Then you have a heap grow limit, that is the maximum growing size of your heap when needed.
Then you have a max heap size. (can be 512Mb on recent phones)

you can have more informations here : http://stackoverflow.com/a/9940415

As you can see before android 3, you don’t have a lot of options.

Thanks for the replies. I trimmed down the scene drastically but I’m not sure if that helped or not (total size of scene j3o + textures is 3.7mb). I tried a suggestion of forcing garbage collection before loading the assets by calling System.gc(); I’m having a new error now:

W/dalvikvm( 5811): threadid=11: thread exiting with uncaught exception (group=0x4156e2a0)
E/com.jme3.app.AndroidHarness( 5811): SEVERE Exception thrown in Thread[GLThread 1733,5,main]
E/com.jme3.app.AndroidHarness( 5811): com.jme3.renderer.RendererException: An OpenGL error has occurred: out of memory
E/com.jme3.app.AndroidHarness( 5811): 	at com.jme3.renderer.android.RendererUtil.checkGLError(RendererUtil.java:125)
E/com.jme3.app.AndroidHarness( 5811): 	at com.jme3.renderer.android.OGLESShaderRenderer.setBackgroundColor(OGLESShaderRenderer.java:407)
E/com.jme3.app.AndroidHarness( 5811): 	at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:965)
E/com.jme3.app.AndroidHarness( 5811): 	at com.jme3.renderer.RenderManager.render(RenderManager.java:1029)
E/com.jme3.app.AndroidHarness( 5811): 	at com.jme3.app.SimpleApplication.update(SimpleApplication.java:252)
E/com.jme3.app.AndroidHarness( 5811): 	at com.jme3.app.AndroidHarness.update(AndroidHarness.java:467)
E/com.jme3.app.AndroidHarness( 5811): 	at com.jme3.system.android.OGLESContext.onDrawFrame(OGLESContext.java:349)
E/com.jme3.app.AndroidHarness( 5811): 	at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1516)
E/com.jme3.app.AndroidHarness( 5811): 	at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)

Perhaps nobody has come across this problem before. Can anyone link me to information about debugging JME on android? Thanks for any help. The test phone is a galaxy s2 btw, would that have anything to do with it (opengl perhaps)?

Howdy Practicing01

I’ve run into this error a trillion times before!

99% of the time you have too big of textures in your scene. Likely you have a texture that is larger than 512x512. It’s best to keep all your textures between 32 and 128 and 512x512 should be your absolute maximum (and you should have a specific reason to do so) and NEVER 1024x1024 (repeat NEVER)

The other 1% of the time you’ll have a hiccup in your game logic that’s causing it.

Big Bob,
I don’t do android dev myself, but sometimes, I saw advices like yours.
Do you know a place (wiki page, thread) where tips/advice/good+bad practice for android are collected/aggregated ?

1 Like


Well I can recall a few started by t0neg0d but they usually just became a trouble shooting place with many posts leading down the wrong path (hacky solutions, or unnecessary logic) until a proper solution was found.

As for a wiki


This page is a wiki, but I’m afraid some of the information may be outdated or misleading as I haven’t found it very helpful when going through a lot of the problems I’ve had.

I’m confident enough to share my knowledge but not enough to edit the wiki (and wouldn’t know how).

But I’ve made more than a few android games and have gained a bunch of knowledge in the quirks of jmonkey and android.

So may be you can start a topic/thread to collect them (starting with your own advices). Then we’ll write a wiki page to aggregate (+ link to discussion).
I think it will be a plus for newcomer in android world and will save lot of time.


1 Like

I’m sure I could give some helpful tips and a good beginner walkthrough (as pretty much all my knowledge of programming has been done with jme’s android).

But I don’t know the etiquette of starting threads and wikipedia pages and such.

Is this normal practice for forums to preemptively post advices on common problems?

I’ve run into a bunch that people would for sure run into and a solid wiki would be good, but once again, I’m not hip to how the whole thing works.

I’m still quite a junior in programming.

IMHO, you start a thread on this topic “sharing advices for android”, (I could start it, if you prefer) where anybody can post its own topics (or comments others). Then later someone (me or any body) will synthesis the content. I’m not a junior in programming, but I don’t have android experience, you’re advices are welcome and if someelse say it’s not a good one, then you and other will know why (context). (I’m not aware of “one size fit all” solution)
I don’t know a better place than the forum to start the collect.

It will be usefull to grab and exchange about your advices.
Tonegod, Monoko_Fan, nehon, you and others have valuables tips to share.

Well if it’s appropriate I will surely start gathering my thoughts and create a topic in the next few minutes.

There are 60 textures in the scene, none of which are larger than 512x512, a total of 885.7kb (the scene j3o is 2.8mb). So I don’t think that’s it. Good to know I shouldn’t go above 512x512 though.


It sounds like it could be the case. What is the average size of each texture?

Do you have a lot that are 512*512?

It would be best to lower them to 128*128.

Erm you calculate wrong.
Save the textures as bmp, and see how large they are then.
-> Gpus use uncompressed textures normally. (+ a few exceptions)

I believe the math is each pixel is 4 bytes of memory so 60 textures at 512512 would be 512512460 which would equal about 60mb (assuming each texture is 512).

I can usually bet my life on the fact that textures cause the problem.

The average is 32x32 and 128x128, converted to bmp the total is 4.8mb. BTW we’re talking about the second error correct? The first error of the post was solved by slimming down the scene as suggested by someone. The second problem seems to be about shaders but I don’t use any (unless the lighting material definition uses them).

@practicing01 said: The average is 32x32 and 128x128, converted to bmp the total is 4.8mb. BTW we're talking about the second error correct? The first error of the post was solved by slimming down the scene as suggested by someone. The second problem seems to be about shaders but I don't use any (unless the lighting material definition uses them).

Yes, of course lighting uses shaders. Both errors are out of memory errors, though.