Jared Malcolm wrote:I think you may misunderstand GC.
Hi Jared thanks for the explanation but I think you misunderstood me. What I was saying is,
At line#10, c1.go(c2) returns null and that means reference c3 has nothing to point. Therefore I wrote
Peeyush Bhadola wrote:At line#10: c3 = null. So there is no object present to be marked for GC.
Also, I am very much aware of the fact what you have mentioned:
Jared Malcolm wrote:if an object no longer has a reference pointing to it...that's the point at which it is ELIGIBLE to become GC'd
... and that is why i wrote :
Peeyush Bhadola wrote:At line#11: c1 = null. That means the remote control(reference) c1 is not pointing to any object and hence the object created at line#8 can be marked for GC.
And in case of reference c2, it is still pointing the object present in memory. So it can't be marked for GC.