please i need help on analysing garbage collection question like this:
how many objects are eligible for garbage collection after executing //line 12
class A{
A a;
public A(A a){
this.a=a;
}
public static void main(String args[]){
A a1=null;
A a2=new A(new A(null));
A a3=new A(a2);
a1=a3;
a1.a=new A(null);
a2.a=null; //Line12
System.gc();
}
}
Ademola Okerinde wrote:please i need help on analysing garbage collection question like this:
please And this 2nd one
how many objects are eligible for gabage collection after executing c.aob = null;
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();
}
}
-----------------------------------------------------------------------------------------------------
how many objects are eligible for garbage collection after executing //line 12
class A{
A a;
public A(A a){
this.a=a;
}
public static void main(String args[]){
A a1=null;
A a2=new A(new A(null));
A a3=new A(a2);
a1=a3;
a1.a=new A(null);
a2.a=null; //Line12
System.gc();
}
}