In your example, three separate objects are created. After the third object is created, the first two would be eligible for garbage collection.
The Garbage Collector in your jvm works on its own cycle, periodically looking for eligible objects. If your program runs short of storage, the Garbage Collector will make an extra pass to try to save you from program termination. System.gc() simply asks the Garbage Collector to make a collection pass. The jvm can either do this or do nothing. The Sun
doc suggests that Sun's jvm's will usually act on your request. Sun even suggests that you can run System.gc() repeatedly until no more memory is recovered.
The main reason for you to call System.gc() is to prevent garbage collection, which takes a certain amount of cpu time, from happening just when a time-critical piece of code is running. However, the execution delay from a garbage collection pass on a modern CPU is very small. System.gc() is also the basis for many exam questions, so it's good to know it even if you never need it in your work.
[ October 23, 2004: Message edited by: Mike Gershman ]