Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Eligible for garbage collection

 
Roger Zhao
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, all:
Given:
12. void start() {
13. A a = new A();
14. B b = new B();
15. a.s(b);
16. b = null;
17. a = null;
18. System.out.println(�start completed�);
19. }
When is the B object, created in line 14, eligible for garbage collection?
A. After line 16.
B. After line 17.
C. After line 18 (when the methods ends).
D. There is no way to be absolutely certain.
E. The object is NOT eligible for garbage collection.
Answer: C
Why not B? We don't know what happened in method s(b). After Line 17, a is eligible for GC, all varibles used in a are all eligible for GC. Right? Plz let me know more about it.

Thanks a lot,
Roger
 
Bert Bates
author
Sheriff
Posts: 8900
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roger -
I think a different answer is correct... Why did you rule out the other answers?
- Bert
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think C is correct. I think is D.
15. a.s(b);
we cannot say what's gonna happen with b in this line.
[ August 29, 2003: Message edited by: Andres Gonzalez ]
 
Reddy Yeluru
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The most correct answer would be D, as we do not have any idea on methos s(b).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic