The first thing that should be mentioned here is that, contrary to this section's title,garbage collection cannot be forced. However, Java provides some methods that allow you to request that the JVM perform garbage collection. For example, if you are about to perform some time-sensitive operations, you probably want to minimize the chances of a delay caused by garbage collection. But you must remember that the methods that Java provides are requests, and not demands; the virtual machine will do its best to do what you ask, but there is no guarantee that it will comply. In reality, it is possible only to suggest to the JVM that it perform garbage collection. However, there are no guarantees the JVM will actually remove all of the unused objects from memory (even if garbage collection is run). It is essential that you understand this concept for the exam. The garbage collection routines that Java provides are members of the Runtime class. The Runtime class is a special class that has a single object (a Singleton) for each main program. The Runtime object provides a mechanism for communicating directly with the virtual machine. To get the Runtime instance, you can use the method Runtime.getRuntime(), which returns the Singleton. Once you have the Singleton you can invoke the garbage collector using the gc() method. Alternatively, you can call the same method on the System class, which has static methods that can do the work of obtaining the Singleton for you. The simplest way to ask for garbage collection (remember-just a request) is
This is not to say that System.gc() is a useless method�it's much better than nothing. You just can't rely on System.gc() to free up enough memory so that you don't have to worry about running out of memory.
We talked to some engineers from Sun while we were updating the SCJP to create the SCJP 6 exam. The consensus was that it's extremely rare, in the Java SE environment, for it to be a good idea to call System.gc(). So, for the SCJP 6 exam we've removed questions that cover System.gc().
But don't be confused - understanding when an object becomes *eligible* for the GC is still very important, and it's still very much on the exam!!