GC Performance problem in 2D game

Hello!

I'm kinda new to java, but have been working with C++ before. Now, I've decided to try and make a 2D online RPG game as a standalone Java application. All is going fine with it, but I am having some performance problems with (probably) the GC:

Each 4-5 seconds there are a 0.5-1 second freeze! It would be great if there was any way to fix this. I am currently using the following Java command line parameters:

-verbosegc -XX:+UseParallelGC

(The -verbosegc is just temporary so I can see some GC output.)

Other then that (the rest of the time) the game runs more or less smooth. This is the output of the GC when the freeze occurred:

[Full GC 13858K->5787K(18304K), 0.0821987 secs]

(Most other lines does not say Full GC.)

I have worked rather hard the last time to fix all memory leaks and such, and now there are none (or very small) leaks left. I don't think I'm over-utlizing objects or w/e it's called.

Is there btw any way to tell the GC to collect a specifig object?

And, does anyone know how other java games and applications does to get rid of problems with the GC?

I have tried experimenting with some heap size parameters, and it works for short times, while the memory fills up, but then it freezes for much longer periods.

Yours, Jiddo.

[1345 byte] By [Jiddoa] at [2007-10-3 9:31:55]
# 1
You cannot force the GC in any way, but you can use the incremental garbage collector, which is meant to prevent such freezes (I think).-Xincgc
Torajiroua at 2007-7-15 4:46:51 > top of Java-index,Java Essentials,Java Programming...
# 2

You may need to give more thought to the way you are using memory.

Try watching the application with JConsole. That allows you to keep an eye on memory usage and garbage collection dynamically.

Are you creating and discarding large arrays that you could reuse?

What kind of -Xmx have you tried?

malcolmmca at 2007-7-15 4:46:51 > top of Java-index,Java Essentials,Java Programming...
# 3

I'll try that JConsole as soon as I get a chanse to.

And, I hardly use any arrays at all (at least not traditional ones). I do use some HashMaps and ArrayLists though.

I have tried some higher and some lower settings. For example 64, 128 and 256. The higher the value the longer the freezes, but as I increase the value, so does the periods without freezes.

Jiddoa at 2007-7-15 4:46:51 > top of Java-index,Java Essentials,Java Programming...
# 4
I have tried -Xincgc, and it worked quite good, but there were still freezes, more often, but smaller. (It's the best so far though.)Yours, Jiddo.
Jiddoa at 2007-7-15 4:46:51 > top of Java-index,Java Essentials,Java Programming...
# 5

Another thing to try is to dramatically increase the size of your "eden" space. This can be collected very efficiently, and it does appear that you have objects that have short lifetimes.

Can't remember the name of the parameter that you want, and it looks like you've already been reading the GC doc, but here's the link anyway: http://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html

kdgregorya at 2007-7-15 4:46:51 > top of Java-index,Java Essentials,Java Programming...
# 6
True. I've been reading parts of that page you linked to, and I'll try that eden thing and see what happens.Yours, Jiddo.
Jiddoa at 2007-7-15 4:46:52 > top of Java-index,Java Essentials,Java Programming...