1.

Suppose We Have A Circular Reference (two Objects That Reference Each Other). Could Such Pair Of Objects Become Eligible For Garbage Collection And Why?

Answer»

Yes, a pair of OBJECTS with a circular reference can become eligible for garbage collection. This is because of how Java’s garbage collector handles circular REFERENCES. It CONSIDERS objects live not when they have any reference to them, but when they are reachable by navigating the object graph starting from some garbage collection ROOT (a local variable of a live thread or a static field). If a pair of objects with a circular reference is not reachable from any root, it is CONSIDERED eligible for garbage collection.

Yes, a pair of objects with a circular reference can become eligible for garbage collection. This is because of how Java’s garbage collector handles circular references. It considers objects live not when they have any reference to them, but when they are reachable by navigating the object graph starting from some garbage collection root (a local variable of a live thread or a static field). If a pair of objects with a circular reference is not reachable from any root, it is considered eligible for garbage collection.



Discussion

No Comment Found