Out of memory, performance issues

Started by RhoX, January 03, 2012, 09:44:54 PM

Previous topic - Next topic

RhoX

Hello everyone,

I've been developing a new game for Android with the jPCT-AE. Recently I've faced a new problem, an error the occurs randomly. Here is the log:

01-03 15:16:01.262: ERROR/dalvikvm(2038): Out of memory: Heap Size=20231KB, Allocated=16823KB, Bitmap Size=4274KB
01-03 15:16:01.282: WARN/dalvikvm(2038): threadid=15: thread exiting with uncaught exception (group=0x4001b390)
01-03 15:16:01.282: ERROR/AndroidRuntime(2038): Uncaught handler: thread GLThread 10 exiting due to uncaught exception
01-03 15:16:01.282: ERROR/AndroidRuntime(2038): java.lang.OutOfMemoryError
01-03 15:16:01.282: ERROR/AndroidRuntime(2038):     at com.threed.jpct.Texture.loadTexture(Texture.java:701)
01-03 15:16:01.282: ERROR/AndroidRuntime(2038):     at com.threed.jpct.Texture.loadTexture(Texture.java:662)
01-03 15:16:01.282: ERROR/AndroidRuntime(2038):     at com.threed.jpct.Texture.<init>(Texture.java:130)
01-03 15:16:01.282: ERROR/AndroidRuntime(2038):     at android.jpct.screening.ScreenRenderer.onSurfaceChanged(ScreenRenderer.java:139)
01-03 15:16:01.282: ERROR/AndroidRuntime(2038):     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1122)
01-03 15:16:01.282: ERROR/AndroidRuntime(2038):     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:977)


This Out of Memory error occurs often, but not always. Actually, sometimes I run my code (in a device) and everything works just fine, other times (without making any changes) I get this error.
I've looked after some performance issues, memory usage, this kind of stuff.. but I still get this error.
Any suggestions?

Thanks in advance

EgonOlsen

Android sometimes behaves a little erratic when working with Bitmaps with an almost filled vm memory. There's no real solution to this other than making it use less memory. How large is that texture? Have you followed these suggestions: http://www.jpct.net/wiki/index.php/Reducing_memory_usage?

yindroid

try to use DDMS tool and watch for heap size!

RhoX

I'm not used to the DDMS tool, but I will try it.

About reducing memory usage, I have followed some of the tips. In fact, I can see the performance difference but the problem still occurs. My textures are all about 512 x 512 (with 285kb) at most - for the skybox - the others are 128x128, 128x64 (with 1.8kb, 1.17kb)... Maybe are the skybox textures too big?

EgonOlsen

As written in the wiki: The file size doesn't matter at all. What matters is the size in memory. 512*512=262144 pixels * 4 bytes = 1mb. One 1mb is needed to store the texture in the gpu's ram (when using 32bit color depth), 1mb for keeping a copy in memory (the upcoming version of jPCT-AE will be able to swap this memory to disk instead...) => 2mb. Plus mipmap, i.e. +256*256*4 + 128*128*4+64*64*4...~ 2.5mb per 512*512 texture. A skybox has 6 textures=> 6*2.5mb = 15mb for the skybox texture alones. As written in the wiki, you can reduce this by defaulting to 16bit textures and compress the in-memory copy.

May i ask which version of Android you are using?

yindroid

very interesting calculations! About cempressions, is it possible on android devices? (android 2.1)

EgonOlsen


K24A3

#7
You have over 16MB already used up so you are running out of RAM when uploading the textures.  The textures themselves don't use much Application RAM after being loaded since they are sent to the GPU VRAM, so you basically need to cut down on the other resources. i.e. use low poly objects or clone the objects if loading the same object multiple times, or load the textures first before anything else.

RhoX

Hello guys, thanks for the help.

Im using Android 2.1 version.
I kinda solved the problem with this links:

http://www.google.com.br/search?ix=icb&sourceid=chrome&ie=UTF-8&q=java.lang.OutOfMemoryError%3A+bitmap+size+exceeds+VM+budget
http://stackoverflow.com/questions/1949066/java-lang-outofmemoryerror-bitmap-size-exceeds-vm-budget-android
http://developer.android.com/resources/articles/avoiding-memory-leaks.html

There are some information about memory leaks, context, static and final variables. My big problem (I think) was the changes between landscape and portrait screens... those was "duplicating" the memory space used by my resources - those links explain better.

Thanks again for all that help! Ill keep it in mind through my development!

ps: K24A3,

I dont know it the problem is related somehow with my objects (for example), cause Im using just a skybox, a plane and a simple human model. But the idea of loading the textures first before anything else is interesting.