I was wondering how the garbage collector in Java deals with the following situation.
Object A has a reference to Object B and Object B has a reference to Object C. The
In fact, garbage collection in java is a very sophisticated thing, far more than in Ruby interpreter, as an example.
Anyway, the theoretical basis is the same.
The GC identifies objects graphs that are no more reachable by program code (that's to say they have no more reference in active code). When talking about object graph, I precisely talk about B->C object graph. once it is unreachable, it can be GC'ed, but you can't tell when it will be, due to the GC trying to optimize as much as possible its work to avoid slowing the application down.