Given:
public class X {
public object m() {
object o = new float (3.14F); //line 3
object [] oa = new object [1];
oa[0]= o; //line 5
o = null; //line 6
oa[0] = null; //line 7
return o; //line 8
}
}
When is the float object created in line 3, eligible for
garbage collection?
A. Just after line 5
B. Just after line 6
C. Just after line 7
D. Just after line 8(that is, as the method returns)
答案C
Given:
1. public class X (
2. public object m () {
3. object o = new float (3.14F);
4. object [] oa = new object [1];
5. oa[0]= o;
6. o = null;
7. return oa[0];
8. }
9. )
When is the float object created in line 3, eligible for garbage collection?
A. Just after line 5
B. Just after line 6
C. Just after line 7 (that is, as the method returns)
D. Never in this method.
答案: D
任何对象名都只是类实例化后,开辟的那一片内存空间首地址的别名
o虽然被null了,但是oa[0]仍然在使用这片空间,所以这片空间是不回被回收的