📄 testgarbage.java
字号:
/*
垃圾回收为一个低优先级的线程。
只有当内存不够时,才会进行垃圾处理
调用finalize();
*/
/*
见JDK API
java.lang.Object中
protected void finalize()
Called by the garbage collector on an object when garbage
collection determines that there are no more references to the object.
*/
class Garbage
{
int index;
static int count; //记录产生对象个数
Garbage()
{
count++;
System.out.println("object "+count+" construct");
setID(count);
}
void setID(int ID)
{
index = ID;
}
protected void finalize()
{
System.out.println("object "+index+"is reclaimed");
}
public static void main(String[] args)
{
new Garbage();
new Garbage();
new Garbage();
new Garbage();
System.gc();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -