Hi All,
This is a question from Devaka's final exam.
How many objects are eligible for GC after line 17?
1. class A{
2. A a1;
3. A a2;
4. public void finalize(){
5. System.out.println("A");
6. }
7. public static void main(
String args[]){
8. A a1=new A();
9. A a2=new A();
10. a1.a1=new A();
11. a2.a2=new A();
12. a1.a2=new A().a1;
13. a2.a1=a1;
14. a2.a1.a2=new A();
15. a1.a1.a1=new A();
16. a1=null;
17. a2=null;
18. System.gc();
19. }
The answer is 7.
Can someone tell me how should we work out these types of questions related to GC?