가비지콜렉션 질문입니다.
가시
1.
class TestA{
TestB b;
TestA(){
b = new TestB(this);
}
}
class TestB{
TestA test;
TestB(TestA test){
this.a = a;
}
}public class ThisProject {
public static void main(String[] args) {
new ThisProject().makeThings();
}
void makeThings(){
TestA test = new TestA();
}
}
정답
The Object referenced by a is eligible for garbage collection.
The Object referenced by b is eligible for garbage collection.
null로 해주지 않아도 가비지콜렉션 대상이 되는 건가요?2.
void start(){
A a = new A();
B b = new B();
a.s(b);
b=null;
a=null;
System.out.println(start completed);
}When is the B object, created in line 14, eligible for garbage collection?정답:
There is no way to be absolutely certain.
s때문에 그런건가요?
-
라일락
아 감사합니다.~
-
뱐헀어
아... 조만간 보내드릴께요~~ 주말이라 연구실을 못가서;;; 일요저녁에 보내 드릴께요~ ^^
-
날샘
밑에 질문에 해석본 보내주신다고 그래서 이 글에 다시한 번 댓글 적은건데여..? 먼저 보내주신다고 그랬어요
-
나빛
너무 많은걸 바라시는듯.. ㅎㅎ
-
찬놀
1. 음.. SCJP 셤 문제인것 같은데... 특정라인이 명시 되어 있지않기때문에 저문장은 맞는것 같네요~
수집되는건 프로그램이 다하면 수집되기 마련이죠..
2. 좀 애매하군요.. s 메소드때문이라고 해도... 그뒤에 a = null; 이 되므로 A 객체도 회수대상이되니깐...