Author Topic: OutOfMemory error occurs when restart game  (Read 3941 times)

Offline androidman

  • byte
  • *
  • Posts: 14
    • View Profile
OutOfMemory error occurs when restart game
« on: May 23, 2011, 06:02:29 am »
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!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: OutOfMemory error occurs when restart game
« Reply #1 on: May 23, 2011, 10:24:18 am »
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....

Offline androidman

  • byte
  • *
  • Posts: 14
    • View Profile
Re: OutOfMemory error occurs when restart game
« Reply #2 on: May 24, 2011, 04:21:37 am »

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()?


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: OutOfMemory error occurs when restart game
« Reply #3 on: May 24, 2011, 10:18:28 am »
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.

Offline androidman

  • byte
  • *
  • Posts: 14
    • View Profile
Re: OutOfMemory error occurs when restart game
« Reply #4 on: May 27, 2011, 07:12:18 am »
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?

Offline dutch_delight

  • int
  • **
  • Posts: 58
    • View Profile
Re: OutOfMemory error occurs when restart game
« Reply #5 on: May 27, 2011, 02:26:37 pm »
I do this in my program but I dont think it's the recommended method:

Code: [Select]
int pid = android.os.Process.myPid();
android.os.Process.killProcess(pid);


Certainly gets rid of everything though.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: OutOfMemory error occurs when restart game
« Reply #6 on: May 27, 2011, 09:25:59 pm »
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.