本帖最后由 严海荣 于 2012-10-9 22:58 编辑
- public class TestEquals{
- public static void main(String args[]){
- for(int i=0;i<10;i++){
- Person p = new Person("Tom" + i);
- for(int j=0;j<1000;j++){
- String[] test = {new String("Asdf"),new String("Billy"),new String("Kessy")};
- }
- }
- }
- }
- class Person{
- private String name;
- public Person(String name){
- this.name = name;
- System.out.println("创建Person对象,name:" + name);
- }
- //---
- public void finalize(){
- System.out.println("销毁Person对象,name:" + name);
- }
- }
复制代码- 创建Person对象,name:Tom0
- 创建Person对象,name:Tom1
- 创建Person对象,name:Tom2
- 创建Person对象,name:Tom3
- 销毁Person对象,name:Tom1
- 销毁Person对象,name:Tom2
- 创建Person对象,name:Tom4
- 创建Person对象,name:Tom5
- 创建Person对象,name:Tom6
- 创建Person对象,name:Tom7
- 创建Person对象,name:Tom8
- 销毁Person对象,name:Tom5
- 销毁Person对象,name:Tom7
- 销毁Person对象,name:Tom6
- 销毁Person对象,name:Tom4
- 创建Person对象,name:Tom9
复制代码 finalize()什么时候调用?好像用到了垃圾回首机制,有大神能具体讲解下么??
|