aspose file tools
The moose likes Java in General and the fly likes Island of isolation Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Island of isolation" Watch "Island of isolation" New topic
Author

Island of isolation

Tom Mark
Greenhorn

Joined: Jun 15, 2011
Posts: 27
Hi,
I'm trying to do self-test of SCJP. But I can't understand why the answer is B. Can anyone explain it?
I thought that in the end three objects will be eligible, but I was wrong.


Given:

3. class Beta { }
4. class Alpha {
5. static Beta b1;
6. Beta b2;
7. }
8. public class Tester {
9. public static void main(String[] args) {
10. Beta b1 = new Beta(); Beta b2 = new Beta();
11. Alpha a1 = new Alpha(); Alpha a2 = new Alpha();
12. a1.b1 = b1;
13. a1.b2 = b1;
14. a2.b2 = b2;
15. a1 = null; b1 = null; b2 = null;
16. // do stuff
17. }
18. }

When line 16 is reached, how many objects will be eligible for garbage collection?

A. 0
B. 1
C. 2
D. 3
E. 4
F. 5
Answer:
✓ B is correct. It should be clear that there is still a reference to the object referred to by
a2, and that there is still a reference to the object referred to by a2.b2. What might be
less clear is that you can still access the other Beta object through the static variable
a2.b1—because it's static.

A, C, D, E, and F are incorrect based on the above. (Objective 7.4)

Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

the same question discussed many times here. search first *
Island of isolation*

and Welcome to JavaRanch
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Island of isolation
 
Similar Threads
Garbage Collection problem-2
How many eligible for gc?
Garbage Collection Clarification
Double K&B Chapter 3- Question 11
Doubt regarding GC