aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Eligible for garbage collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Eligible for garbage collection" Watch "Eligible for garbage collection" New topic
Author

Eligible for garbage collection

Roger Zhao
Ranch Hand

Joined: Aug 05, 2003
Posts: 73
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


"There is a will,there is a way!"<br />SCJP1.4
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8764
    
    5
Roger -
I think a different answer is correct... Why did you rule out the other answers?
- Bert


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
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 ]

I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
Reddy Yeluru
Greenhorn

Joined: Aug 18, 2003
Posts: 18
The most correct answer would be D, as we do not have any idea on methos s(b).
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Eligible for garbage collection
 
Similar Threads
garbage collection
A GC Question
Help! GC question #1.
I think D is right, but someone told me C is right.