In the below example program how many object will be garbage collected before executing line Thread.sleep(1000)?
public class GCExample {
public static void main(String[] args) throws InterruptedException {
GCExample gc = new GCExample();
gc.doSomeThing();
Thread.sleep(1000);
}
public void doSomeThing(){
Object[] obj = new Object[2];
for(int i=0;i<obj.length;i++){
obj[i] = new Object();
}
}
}
Given the non-deterministic nature of GC, I’d say about the same number as fit the length of a piece of string.