1
package test;2

3

class TestGC
{4
private String str = "hello";5

6

TestGC(String str)
{7
this.str = str;8
}9

10

public void finalize()
{11
System.out.println(str);12
}13
}14

15

public class Hello
{16

17

/** *//**18
* @param args19
*/20

public static void main(String[] args)
{21
// TODO 自动生成方法存根22
System.out.println("hello");23

24
TestGC test = new TestGC("test1");25
test = new TestGC("test2");26
test = null;//注释掉这一句,test1被回收。加上则先回收test2,后test127
System.gc();28
}29

30
}31
