浅谈Java对象回收的三种方式

时间:2023-03-08 19:40:14

半夜睡不着,加上最近在看Java虚拟机,写点给新手和自己看的东西。

第一类:生命周期中止

void scope(){

   Test t = new Test();
}

第二类:对象无引用

(一)、对象的应用被转移:

void life(){
Test t = new Test();
t = new Test();
}

(二)、对象被赋值为null

void scope(){
Test t = new Test();
t = null;
}