How many objects are eligible for garbage collection after line1?
public class Test{
public static void main(String args[]){
Test test=new Test();
String[] s=test.f() //line 1
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;
}
}
Ans: 3
But i think its 2...
How is it 3???