OutOfMemory error occurs when restart game

Started by androidman, May 23, 2011, 06:02:29 AM

Previous topic - Next topic

androidman

Hi all,

When i start my game after the first time ( when it was installed), all the previously loaded graphic data(ex. texture, object3D, ....) is not erased and it  is loaded again and again  till the buffer OutOfMemory error occurs. After the error occurs, all data is erased. How to erased that data when exiting the game?

I am sorry if this is a very simple mistake!

EgonOlsen

I'm not sure what you want to achieve!? Do you really want to clean up the resources and load them again or do you want to keep the resources in memory without loading them again or should an exit really be a hard exit that kills everything just like the OOM-crash does? In that case, you can always exit the VM the hard way with System.exit....

androidman


Firstly, thanks for your answer!!!

Yes, I want to delete all of resources when game was exited and reload them at the next start time. I can use System.exit(). But i don't understand why data wasn't deleted when game was exited even though i closed the main activity! Where are resources stored? Does jpct manage this storing? How can i do the completly erasing without using System.exit()?


EgonOlsen

That's impossible to say without knowing what you are actually doing. Keep in mind that stopping the activity doesn't terminate the VM. In addition, the GPU will hold some data like textures and maybe geometry as long as the gl context is valid. You can always unload and flush everything, but if all you want is to clean up everything, i suggest to use a simple System.exit. It's not very elegant, but less code for the same effect.

androidman

At the game starting process, i already excuted TextureManager.flush() and when activity is destroyed, i set glSurfaceView = null.

But it's not work. How can i flush GPU memory?

dutch_delight

I do this in my program but I dont think it's the recommended method:

int pid = android.os.Process.myPid();
android.os.Process.killProcess(pid);


Certainly gets rid of everything though.

EgonOlsen

There's actually no need to flush and reload stuff. As long as the vm instance exists (which has nothing to do with the Activity), the textures remain in the manager and can be reused. If you want to make you app to be able to get paused and resumed, have a look at the HelloWorld example. It uses a static variable to store/restore the Activities current state.
If you don't want/need that, a System.exit is sufficient. There's usually no need to flush the manager.

The data on the gpu should be unloaded, when the gl context is lost. If the Activity gets destroyed, this will also happen.