Java – What triggers a full garbage collection in Java

garbage-collectionjavaperformance

I'm wondering what are the exact situations that trigger Full Garbage Collection in Java.

The obvious ones are:

  • Running out of old gen
  • Running out of perm gen
  • Calling System.gc()

What about other cases that cause full gc? Particularly:

  • Not having enough free space in Survivor Space to copy objects from Eden.
  • Minor collections not being able to cope with allocation rate of new objects (don't know how though).

I'm running Sun Java 1.6 and using Concurrent Mark-Sweep and ParNew for new gen.

Best Answer

I've observed one more situation that triggers a full GC in Java Hotspot VM 1.6 64bit on Ubuntu, using Concurrent Mark-Sweep:

If -XX:PermSize value does not equal to -XX:MaxPermSize (e.g. is smaller), an occasional Full GC happens when java needs to expand the PermGen (even though it does not need to allocate more memory than MaxPermSize). So setting -XX:PermSize and -XX:MaxPermSize to be the same seems like a good idea.