Hi,
while drawing GV diagram , i can see that only one object is eligible for GC but the answer gives 2. CAn you plz check:
class A{ A aob; public static void main(String args[]){ A a=new A(); A b=new A(); A c=new A(); a.aob=b; b.aob=a; c.aob=a.aob; A d=new A().aob=new A(); c=b; c.aob=null; System.gc(); } }
Hi Vikram,
There ARE two objects eligible for the garbage collector. Namely, the object created at the line-6, and one of the two objects created at line-10 becomes eligible at the end of the given code fragment. Solving this sorta questions would be much easy if you watch our garbage collection video:
http://www.examlab.org/v/garbage-collection
Can you please let me see the diagram you created so we can figure out where you had a problem on?