class Bar{}
class Test{
Bar doBar(){
Bar b=new Bar();
return b;
}
public static void main(String arg[]){
Test t=new Test();
Bar newBar=t.doBar();
System.out.println("new bar");
newBar=new Bar();
System.out.println("finishing");
}
}At what poing is the Bar object,create on line 3,eligible for garbage collection?A.after line 8;
B.after line 10;
C.after line 4,when doBar() completes.
C.after line 11,when doBar() completes.
class Test{
Bar doBar(){
Bar b=new Bar();
return b;
}
public static void main(String arg[]){
Test t=new Test();
Bar newBar=t.doBar();
System.out.println("new bar");
newBar=new Bar();
System.out.println("finishing");
}
}At what poing is the Bar object,create on line 3,eligible for garbage collection?A.after line 8;
B.after line 10;
C.after line 4,when doBar() completes.
C.after line 11,when doBar() completes.
我还没看懂!要看懂了这句我应该可以解释,我这里没翻译工具!
Bar doBar(){
Bar b=new Bar();
return b;
}//上面的方法中,创建的对象始终由b引用,这个地方会出现内存泄漏。