class Person
{
String name;
int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
Person(String name,int age)
{
this.name=name;
this.age=age;
}
@Override
public void finalize() throws Throwable {
System.out.println("回收"+this+"");
}
}
public class SystemDemo {
public static void main(String args[])
{
//当前时间
//long start=System.currentTimeMillis();
//System.out.println(start);
//垃圾回收--相当于调用Runtime类的gc()方法
//System.gc();
//object类中存在一个方法,在垃圾回收前进行处理finalize();
Person p=new Person("张三",99);
p=null;//取消引用
System.gc();
}
}