I’ve created some side scrolling code that works silky smooth except for an occasional pause. I’ve tracked this pause back to the garbage collector (what else) running every once in awhile for anywhere from 70 to 100 ms. My loop is free of garbage save for one possibility: the graphics object. Every loop of the BufferStrategy creates a new Graphics object (I’ve verified this in the Java source) which eventually collects into enough to require a full garbage collection. The perfect solution (of course) is for Java to reuse the graphics contexts on VolatileImages. Barring that, has anyone figured out a good way to handle the garbage collector in 2D code?
you are letting your threads sleep, right? otherwise the GC have a lot of garbage to collect. it only does that when there is too much garbage and hence the pause. by letting your threads sleep a little every now and then the GC can do a little collecting but very often resulting in smoother execution.
hope it makes sense.
Also, try using incremental gc.
[quote]you are letting your threads sleep, right? otherwise the GC have a lot of garbage to collect. it only does that when there is too much garbage and hence the pause. by letting your threads sleep a little every now and then the GC can do a little collecting but very often resulting in smoother execution.
[/quote]
I added Thread.yield() (since I didn’t want to give up a precious, whole millisecond) and it smoothed out. It still makes barely perceivable jumps every once in awhile, but I only notice because I have a trained eye. To everyone else, it’s silky smooth. Thanks, mill!
anytime