System类-gc()
2017-01-07 16:12
148 查看
一 gc()
运行垃圾回收器。二 代码
1.构造一个Person类(重写finalize)2.实例化一个Person类
3.回收Person类
/** * Created by hanshan on 2017/1/7 0007. */ public class gcDemo { public static void main(String[] args){ //实例化Person类 Person p=new Person("小明",14); //回收Person p=null; System.gc(); } }
package gcDemo;
/**
* Created by hanshan on 2017/1/7 0007.
Person类
*/
public class Person {
String name;
int age;
public Person(String name) {
this.name = name;
}
public Person(String name, int age) {
this.name = name;
this.age = 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;
}
@Override
protected void finalize() throws Throwable {
super.finalize();
System.out.println(this.name+"被销毁");
}
}
相关文章推荐
- 最简单的Btrace查询System.gc的调用
- Java finalize() 和System.gc()
- 实战Java虚拟机之四:提升性能,禁用System.gc() ?
- void java.lang.System.gc()
- java垃圾回收那点事(一) System.gc开始说起
- system.gc()和system.runFinalization()区别作用
- 如何让System.gc()更快的工作
- finalize()和System.gc()的区别
- android垃圾回收机制及程序优化System.gc
- android垃圾回收机制及程序优化System.gc
- 浅谈Java中的System.gc()的工作原理
- actionscript垃圾回收机制 System.gc()
- 在VC++.net中将System::String __gc* 转换为本机的char *或wchar_t *的三种方法
- System.gc与finalize以及Thread对象何时被回收
- System.gc()
- RHEL 6.2 Error: Cannot create GC thread. Out of system resources.
- System.gc()与Object.finalize()的区别
- System.gc()和System.runFinalization()
- 调用System.gc没有立即执行
- System.gc(); 与Runtime.gc()的区别