although garbage collection is explained well in K & B but still I am getting confused in it.
Suppose a situation when we are making a reference null, then there should be only one object eligible for null.
but why it is showing that more than one object(incase that object itself contains link to other int or short) eligible for null.
all the question related to garbage collection is confusing me in one way of its answer.
I dont think that more objects will be eligible for gc if the object itself contains int or short.
However if the object contains references to other objects then those will also be eligible for GC since there is no way of reaching them them if you remove the reference to the enclosing object by setting its reference to null.
"An object is eligible for gc when no live thread can reach it" - Quote from K&B
One of the big reasons that GC is on the exam, is that if you're not careful, your BIG JAVA PROGRAM, might not ever give the garbage collector objects to collect. So it's important to understand ways in which you can release objects when you're done with them AND it's important to understand bugs that can occur when you think you've released an object, but you really haven't.
So, see if you can answer this question: "What's the lifetime of a static variable?" See if that answer helps you understand this question.
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop