There's no way to completely avoid full GC but there are some tricks you can use.Firstly, don't generate so much garbage if you can help it Secondly, try tuning the heap size so the amount of garbage that can accumulate before a collection isn't so bigThirdly, try the incremental collector (-Xincgc) and/or the parallel collector (can't remember the switch).Fourthly, try calling System.gc() at points in the game where a GC won't be noticed (in between levels for example)

I can't remember -Xms's default but -Xmx defaults to 64mb. You might not need quite so much.There's a new flag now, -XX:+UseAdaptiveSizePolicy, which tunes the size of the Eden space as well, which helps prevent stuff getting promoted into the main heap too early in the first place.

The larger it is, the less often you will fullGC, but the greater the pause wil lbe when it does.Also you NEVER want tos et max heap so big you start swapping to disk at run-time.

As much as possible, if you can get away with it (you cant always) it good to let the system work these thinsg out.

I think however you may be putting the cart before the horse. You have not yet determiend *why* yo uare seeing full GCs during game-play. Most games dont because they only do two kidsn of allocations:(a) Short lived objects that live in the eden space and never promote.(b) Objects that exist for the entire level and only get freed up and GCd at level chnage.

Step one of performance tunign is always, always, always to profile your code. It might be that it is an object leak that is causing your entire problem.

Got a question about Java and game programming? Just new to the Java Game Development Community? Try my FAQ. Its likely you'll learn something!

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org