class TestA {
TestB b; TestA() {
b = new TestB(this);
}
}class TestB {
TestA a;
TestB(TestA a){
this.a = a;
}
}class TestAll {
public static void main(String[] args){
new TestAll().makeThings();
//...code continues on
}
void makeThings() {
TestA test = new TestA();
}
}
这个程序中 在 //...code continues on 这句话之前,变量 a 和 b 都被垃圾回收掉了,请问这是为什么??我不理解
一个在栈中,一个在堆中形参在方法执行完后就会从栈中回收掉
而成员变量要在对象被回收时才被回收
这明显是两个对象相互引用
这样也会被垃圾回收吗?