The JVM does garbage collection for us. The algorithms are wonderfully complex and varied. It seems every new release of the JVM has improved gc. Googling on "Sun garbage collection algorithm" got a few hits like
THIS. Note it is specific to one particular dot release of the JVM.
This is a fascinating area, but one we really should stay away from in coding. Don't try to optimize your code for some particular gc version, or try to invoke the gc yourself to improve performance. I trust that it is far smarter than I am, and it is likely to change in ways that will make my optimization today the worst possible choice tomorrow. So read it, be impressed, and try to forget.