This is a question I have from Lecture about the discussion of Garbage Collection. I cannot figure which line cause the garbage collection.
I have tried using the compiler to run the programming and the outputs are
#1: [C001, C002]
#2: [C001, C002, C001]
#3: [C001, C002, C001]
I know that there is a line that cause Garbage Collection but I cannot figure it out. At the same time, professor required us to draw a diagram showing how the objects and data, lists go.
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
Customer a = new Customer("C001");
Customer b = new Customer("C002");
ArrayList<Customer> list1 = new ArrayList<Customer>();
list1.add(a);
list1.add(b);
System.out.println("#1: " + list1.toString()); Icdddd
ArrayList<Customer> list2 = new ArrayList<Customer>();
list2 = list1;
list2.add(a);
System.out.println("#2: " + list1.toString());
System.out.println("#3: " + list2.toString());
}
}
System.gc()).