1.

Explain the reference counting mechanism in context to Garbage Collection.

Answer»

From the beginning, the REFERENCE counting MECHANISM has been a very old Garbage Collection technique. Each object in the reference counting approach has a track of the number of pointers to it from various OBJECTS and the stack. When a new item refers to it, the counter is increased by one. When an object's reference is lost, the counter is decremented by one. When the count hits '0,' the garbage collector can de-allocate the object.

When allocating to a new object, the main advantage of the reference counting approach has been the low amount of work per memory write. HOWEVER, it has SERIOUS difficulty with data cycles. When the first object is referred to by the second object, and the second object is referred to by the first (cyclic references), the count never reaches 0, and the objects are never garbage collected.



Discussion

No Comment Found