关于垃圾回收
上次我不知道看谁帖子的,还是和谁讨论的,说垃圾回收是的候选时刻是刚好没有引用指向堆中的此对象时候,但是用这个规律套这道题目好像不怎么正确?谁帮忙解释下?
Question 209
Given:
11. public void genNumbers() {
12. ArrayList numbers = new ArrayList();
13. for (int i=0; i<10; i++) {
14. int value = i * ((int) Math.random());
15. Integer intObj = new Integer(value);
16. numbers.add(intObj);
17. }
18. System.out.println(numbers);
19. }
Which line of code marks the earliest point that an object referenced
by intObj becomes a candidate for garbage collection?
A. Line 16
B. Line 17
C. Line 18
D. Line 19
E. The object is NOT a candidate for garbage collection.
Answer:D
我感觉,既然intObj是个循环体中定义的局部引用,那么它的生命期应该旨在循环体中有效吧,那么应该选择B阿,为什么选择D呢?