class TestA {
TestB b;
TestA(){
b=new TestB(this);
}
}
class TestB{ TestA a;
TestB(TestA a){
this.a=a;
}
}
class TestAll{ public void static main(String[] args){
new TestAll().makeThings();
//...code continues on
}
void makeThings(){
TestA test=new TestA();
}
}
The object referenced by a is eligible for garbage collection
The object referenced by b is not eligible for garbage collection
TestB b;
TestA(){
b=new TestB(this);
}
}
class TestB{ TestA a;
TestB(TestA a){
this.a=a;
}
}
class TestAll{ public void static main(String[] args){
new TestAll().makeThings();
//...code continues on
}
void makeThings(){
TestA test=new TestA();
}
}
The object referenced by a is eligible for garbage collection
The object referenced by b is not eligible for garbage collection
The object referenced by a is eligible for garbage collection
The object referenced by b is not eligible for garbage collection
(中文翻译:为什么 a 引用的对象符合垃圾回收条件,b 引用的对象不符合。)请看清楚题目在回答阿