日期:2014-05-20  浏览次数:20528 次

java垃圾回收问题
当对象没有引用的时候会被自动回收嘛,
还有一种语法是直接new 一个对象出来,
像: new ArrayList<Integer>().add(1);
上面这种情况怎么是怎么判断回收不呢?
------最佳解决方案--------------------
你把print改为System.out.println,我引入了一个包中的方法
------其他解决方案--------------------
丢失引用,jvm调用finalize方法。但是至于什么时候执行,什么时候这块空间被释放这就要看jvm了。
------其他解决方案--------------------
刚刚入门,学习了
------其他解决方案--------------------
package org.test;
import static net.mindview.util.Print.*;
class Bowl
{
int i;
//Bowl(){ print("Bowl default con"); }
Bowl(int i){ this.i=i; }
public void finalize()
{
print("回收对象"+i);
}
}
public class Test 
{
public static void main(String[] args)
{
new Bowl(2);
Bowl b1=new Bowl(1);
System.gc();
}
}

输出结果:回收对象2
------其他解决方案--------------------
临时对象会被回收的
------其他解决方案--------------------
引用:
Java code?123456789101112131415161718192021package org.test;import static net.mindview.util.Print.*;class Bowl{    int i;    //Bowl(){ print("Bowl default con"); }    Bowl(int i){ this.i=……

怎么没看到显示信息喃
------其他解决方案--------------------
不好意思,有人盗我号上来发帖,奖励平分,鄙视这种程序员的败类