垃圾收集了多少个对象?

Sri*_*ula 0 java

在下面的示例程序中,在执行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();
    }
}
Run Code Online (Sandbox Code Playgroud)

}

spe*_*der 6

考虑到GC的非确定性,我会说一个与一段字符串长度相同的数字.