can anyone please explain how and what two objects are eligible for gc? I am really confused in this GC topic . I have seen the link referred above and have understood that example , but this one is really difficult. Anyone please explain.
i was considering the object referenced by s1.a1.a2.a2.a1..
According to me...
s1 is referring to an object..
.then s1.a1 will be further extension like
s1------->s1.a1
then s1=s1.a2,so they are referring to same object
then s1 or s1.a2---------->s1.a1.a2------------->s1.a1.a2.a2---------->s1.a1.a2.a2.a1;
Again due to
s1.a2.a1.a2=null;;
Since s1.a1=s1..i will refer this as s1.a1.a2 ok?
so s1.a1.a2 will be referring to null.......and hence further s1.a1.a2.a2 's object will not be referring to anything...so are "these" objects eleigible for Gc???
what about the object made by s1.a1.a2.a2.a1 since it is no longer pointing to its first object ..it is pointing to latest s1.a1's object.....???
thanks...
s1---------------> object A and it contains two reference variable a1 and a2 pointing to null at the moment
s1.a1---------------> another object A that again contains two reference variable a1 and a2 pointing to null at the moment
s1.a2 = s1 ---------> means s1.a2 points to object refered by s1.
s1.a1.a2-------------> yet another object A that contains two reference variable a1 and a2 pointing to null at the moment.
s1.a1.a2.a2------------> yet another object A that contains two reference variable a1 and a2 pointing to null at the moment.
s1.a1.a2.a2.a1=s1.a1-------> means both of them point to same object which was s1.a1 was pointing.
s1.a2.a1.a2=null----------> means object refered by s1.a1.a2 becomes null (since s1 and s1,a2 refers to same object there a1 reference variable is same)
so now object refered by s1.a1.a2 has no live reference and hence object refered by s1.a1.a2.a2 also loses any live references.
and hence these 2 objects become eligible for gc.
saima kanwal wrote:can anyone please explain how and what two objects are eligible for gc? I am really confused in this GC topic . I have seen the link referred above and have understood that example , but this one is really difficult. Anyone please explain.
the best way to solve gc question is drawing a diagram.