Profiles of active garbage collection revealed some fundamental flaws in how GC algorithms worked versus how garbage needed to be collected. Most objects in a running application only live for a short while and a select few live the entire life of the application. The algorithms outlined above treat all objects equally. Unfortunately, every active object requires some work upon it (e.g., shuffling, marking), which negatively affects performance. Objects that live a long time are continuously -- and needlessly -- shuffled around as they survive collection to collection. Contemporary garbage collectors like the one in the latest Java Hotspot VM create separate pools for younger and older objects called generations. If an object survives a specific number of collections (sometimes just one, but it depends on the collector), it is moved from a younger pool to an older pool. The older pool is, by nature, collected less often in hopes that, since these objects have lived awhile, they're likely to live awhile longer. The effect is a greatly reduced load upon the garbage collector. Short-lived objects that die inside a collection cycle have less impact on the collector since collectors mostly deal only with live objects. Older generations are collected far less often, reducing the needless shuffling of old objects. Different generations can even have different algorithms used within them. For example, a stop and copy is suitable for the young object pool since it is assumed most young objects die quickly (stop and copy has a linear performance cost in respect to the number of nongarbage objects). Older generations can take extra steps towards exacting algorithms since performance is less of an issue. Put garbage collection to good use
For all its merits, garbage collection still takes CPU cycles away from a running program. The best way to minimise that impact is to simply create fewer objects. Fewer objects provide fewer collections, which theoretically improves performance. garbage collection is a solid step toward taking away some nasty details from everyday programming. It was a hot topic of research in years past and most of the technology used today is quite old (in computing terms anyway). It is about time you put garbage collection to good use.






