Hi everybody: My final day for SCJP has come. Tomorrow is the day. I'm nervous but confident. To he point: I don't understand the meaning of "Islands of Isolated Objects". How can I know when an IIO is elegible for garbage collected? Thanks,
Enrique Villamizar P.S. English isn't my first language.
They are eligible for garbage collection when they are not referred to by anything other than each other.
For example, say you have an object a, which nothing refers to. That's available for GC, right? If b refers to a, then a is not available for GC. However, what if the only reference to a is from b, and the only reference to b is from a? Then a and b represent an "island", and should both be garbage collected.
after line 9 runs, how many objects are elgible for garbage collection? At first I thought none. But the answers is two. What happens for example with x2.x and x3.x? they are objects too, aren't they? To be honest I don't understand this K&B question.
Enrique Villamizar P.S. English isn't my first language.
The objects created in the first two lines of main method will be GC'd. X2 x2 = new X2(); X2 x3 = new X2();
Even though these both object have references between each other, these objects will be GC'd because "these two objects cannot be reached from any of the threads in jvm". If they cannot be reached, why they should be there ? So they will be GC'd.
No, tomorrow we rule the world! With this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss