What is the disadvantage of garbage collection?
We know that an object is ready to garbage collected if it is not reachable by any reference. JVM has the facility for the reference counting. Suppose a parent object that has a reference to its child object, which has a reference back to its parent. These objects will never have a reference count of zero even though they may be unreachable by the roots of the executing program. Another disadvantage is the overhead of incrementing and decrementing the reference count each time. Because of these disadvantages, reference counting currently is out of favor.
Garbage collection have some disadvantages:
* The application�s working set may be larger.
* Performance may not be as good as if you hand-optimize memory management (for more details, see �Performance�).
* A common design pattern whereby resources are tied to the lifetime of objects does not work effectively under GC.
* You must ensure that for any object you want to be long-lived you maintain a chain of strong references to it from a root object, or resort to reference counting for that object.