Lab 1 Solution

After which line is the object at line 6 eligible for garbage collection.

1: public class RefObj {
2:
3:   private RefObj ref;
4:   
5:   public static void main(String[] args) {
6:      RefObj a = new RefObj();
7:      RefObj b = new RefObj();
8:      b.ref = a;
9:      a = null;
10:     RefObj c = a;
11:     b = null;
12:   }
13: }

a is new object

b is new object

b ref points to a

a is broken, but b.ref still points to a

c points to a null

b is broken

It is eligible when the method finishes.


Prev -- Up