out of memory error

Started by
12 comments, last by zhick27 13 years, 7 months ago
Hello there! Well I just created a game that have main menu on it.


But when I try to play new game then go back to main menu then play again... until some times its stop

and error was displayed: java.lang.OutOfMemoryError

Do you know guyz how to fix this?
Advertisement
Debugger.
Sounds like your program leaks.
Do you know how to fix this? Coz I need to finish this ASAP.. :(
Quote:Original post by zhick27
Do you know how to fix this?

Yes.

Yes.
Come on guys...

Well, it looks like you do not clean things up somewhere and they don't get released. Look at your code when you return from the game state and see if you keep references to it somewhere.

That's all that's possible to tell without seeing any code and/or more details. Your description is incredibly vague.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Ok thanks for the reply...

What are the things should be done in order to fix this?

BTW here is the part where new game will be started:

public void newGameScreenShow(int level, int score) {

try {
this.mainMenuScreen = null;

this.gameCanvas = new SaveTheTamarawCanvas(this, level, score);
this.gameThread = new Thread(this.gameCanvas);
this.gameThread.setPriority(10);
this.gameThread.start();
this.display = Display.getDisplay(this);
this.display.setCurrent(this.gameCanvas);
}catch (OutOfMemoryError oome) {
System.out.println(oome);
}

}

Tell me pls if you need also some other codes of my game to fix this
Use oome.printStackTrace(), this will show you the exact line the exception occurred on. This won't necessarily be the place where all the allocations happen, but it might give you a clue.

Other than that, it is really difficult to say. One possible culprit is the JVM, which will limit itself to some subset of memory (probably only a few hundred megabytes by default). You can change this configuration by using the -Xmx parameters when creating the JVM, but only do this if you know you need to use more than the default maximum amount of memory. Otherwise you are only masking the problem, and it will bite you after 15 minutes of play rather than 5.

Another culprit to remember is that Java's garbage collection only manages memory, it does not free system resources such as textures. Speaking of textures, if you are not caching and sharing textures you could easily run out of memory before you think you should.

As Endurion mentioned, in order for garbage collection to kick in you must ensure that object graphs become detached. Creating threads like you have is a great way of creating a large set of object graphs that will live forever if you aren't careful.

This is an architectural issue. How do you clean up between levels? How do you dispose of the menus?

I believe there are tools for examining the Java heap. Even a simple breakdown of the types of objects that are consuming the majority of the memory would be really helpful in terms of finding the root cause.

Another possiblitly is simply printing the value of the freeMemory(), maxMemory() and totalMemory() values of the Runtime class somewhere. You might be able to correlate memory spikes with specific actions in your game. But this is a fairly crude way of doing this.
when i printed the oome.printStackTrace() the output is this: TRACE: <at java.lang.OutOfMemoryError>, Exception caught in Display class.

Well I know now that its on the display class but there are so many displays I use on the game. My assumption is that its on my game canvas but I don't know where on my code is that.

This topic is closed to new replies.

Advertisement