Labs
These labs require drawing references to objects on the heap.
-
After which line is the object created at line
4eligible for garbage collection?Lab 1 Solution1: public class GCObj { 2: public static void main(String[] args) { 3: GCObj one = new GCObj(); 4: GCObj two = new GCObj(); 5: GCObj three = one; 6: one = null; 7: GCObj four = one; 8: three = null; 9: two = null; 10: two = new GCObj(); 11: } 12:} -
After which line is the object at line
6eligible for garbage collection.Lab 2 Solution1: 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: }