posted 16 years ago
Hmmmm.... This would be an interesting one to draw out.
Let's name the objects OA, OB, OC, etc., as they are being created. This is to distinguish them from the references. Also, let's follow the aob reference of the objects, in order to get the full graph. So...
---------------------------
After:
A a=new A();
A b=new A();
A c=new A();
We look like this...
---------------------------
After:
a.aob=b;
b.aob=a;
c.aob=a.aob;
We look like this...
---------------------------
After:
A d=new A().aob=new A();
We look like this...
note: object OD is not reachable after this line.
---------------------------
After:
c=b;
c.aob=null;
We look like this...
So... We lost access to objects OC and OD. Those two objects are no longer reachable.
Hope this helps, and please correct me if I missed anything...
Henry
[ November 15, 2008: Message edited by: Henry Wong ]