Jump to content
  • Advertisement
Sign in to follow this  
zhick27

out of memory error

This topic is 2952 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!