Can anybody tell how many object are eligible for gc after line 1 and how(Whizlab question). I thought the answer was 2. But the given answer is 3.
public class
Test {
public static void main(
String[] args) {
Test test = new Test();
String[] s = test.f()//line1
System.gc();
Thread.sleep(2000);
}
public String[] f() {
String[] s = new String[4];
for (int i=0;i<s.length;i++)
s[i]= new String(""+i);
String[] s1 = new String[2];
s1[0] =s[0];
s1[1]=s[1];
return s1;
}
}