This is a question posted in the "Java Developers" group on LinkedIn. I'm not the original author.
After line 14, how many objects are eligible for garbage collection?
According to the
thread's author, the answer is 2, but I only count 1.
My understanding is that
ob1 in Line 3 is a copy of a reference. When the reference changes at Line 5,
c1 still maintains a reference to the object created in Line 11.
Therefore, the only object I see eligible for garbage collection is created in Line 05. It becomes unattached when
c2 changes it's reference to
c3 in Line 14.
Is my analysis incorrect?