请看下面的程序运行的结果,为什么垃圾回收器会连续回收两个最近的对象(4731hello2,4730hello2)然后再从最前面回收(hello1)然后又回收两个最近的对象(4729hello2,4728hello2)然后回收当前最前面的对象(1hello2)
而以后的规律却变成了1.回收当前最近的对象(4727hello2)2.回收当前最久的对象(3hello2)3.重复执行上面1、2两个步骤。
我的系统是winxp   jdk 用的是 1.6.0-beta2为了能看到了这么多行结果我在Eclipse 中运行了这个程序
是不是所有的垃圾回收都是按这个规律回收的呀,
还是跟本就没有什么规律
我想知道它的工作过程public class test {   
    static long time=1;
    public test() {
    }    
    public static void main(String[] args) throws Exception{        
        System.gc();
        hello1 h1=new hello1();
        h1=null;             
        for(long t=0;t<10000;t++){  
    
              System.out.println(t); 
        
              hello2 tt=new hello2(); 
                      
             if(t<4744) time=1;//经过多次实验,我的机子会在这附近进行垃圾回收
             else time=500;
            Thread.sleep(time);  
       
        }       
    }
}
class hello1{
    static long count;
    long con=0;
    hello1(){
     count++;
     con=count;
    }    
    protected void finalize(){
        System.out.println("回收第"+con+"hello1");
    }    
}
class hello2{
    static long count;
    long con=0;
    hello2(){
     count++;
     con=count; 
     }
    protected void finalize(){
        System.out.println("回收第"+con+"Hello2");
    }
}
某一次程序执行后显示的代码:12......47304731
回收第4731Hello2
回收第4730Hello2
回收第1hello1
回收第4729Hello2
回收第4728Hello2
回收第1Hello2
回收第4727Hello2
回收第2Hello2
回收第4726Hello2
回收第3Hello2......