JOGL vs Garbage Collector, Its killing me!

I’ve been porting a game engine I’ve worked on for almost 2 years to (Java and JOGL) from (Visual Basic.Net and DirectX). My final project for my design patterns class used my engine to make a Mario game. I’ve tried implementing a Recycler but it proved to be slower, and I’ve changed several options for the GC and the VM. Throughout playing the game (sometimes not at all) The garbage collector will kick in and take up a whole second to clean everything up. When this happens the screen appears to freeze, then once it updates again everything has moved drastically because of the time since the last update (obviously every thing’s time based). I’m trying to find out how to avoid this happening altogether at all costs because I can’t make a successful game engine unless everything works right. The problem may be me wanting to run the game at full speed and it doesn’t give that much time if any for the GC to do its job. If I used the FPSAnimator option and set the FPS to about 60-100 (opposed to my normal 200-400) everything seems jumpy and not smooth. Could this be because my timer uses System.nanoTime()? Any suggestions on improving it?

use a profiler and find the methods that produce a lot of garbage. rewrite them so that only the “small” collection happens. major collections will always freeze the screen for a second.

see the performance forum and this thread on how to minimize garbage collections
http://www.java-gaming.org/forums/index.php?topic=16512.0

Thanks that thread really helped out a lot, I’ve been trying to find this sort of information on it but Google just doesn’t cut it sometimes. Apparently setting all my variables to null after I’m done with them is a bad thing, I did that to every single variable I used. Hopefully when I get done updating it and making it more efficient Ill see if it made a big impact… hopefully.

might be worth while for you to have a look at Yourkit profiler (15 day full eval available), and also keep an eye on your garbage collection via jconsole or visualgc. The profiler also lets you snapshot and browse the heap so you can identify if excess garbage is really your problem. Might be worth posting your current jvm configuration options for some more feedback. Or a screen shot of visualgc after running for a while.
So far I don’t re-use any objects, or tweak the GC, or do anything fancy with pooling and things are pretty smooth. Object creation is low overhead in Java these days, and the parallel garbage collectors quite efficient, if you have the memory pools configured nice.

Cheers
Peter

Hi, you can also simply use Netbeans profiler, which is free and fulfills a lot of needs to inspect memory.

[quote]and the parallel garbage collectors quite efficient, if you have the memory pools configured nice.
[/quote]
Can you elaborate on this? How can I set it up so that when someone uses my GameEngine the VM uses parallel GC and that the memory pools are configured ‘nicely’. I’m new to java and how the JVM works, I’m used to programming games with Managed DirectX and XNA.