After the comment line how many objects are eligible for garbage collecton?
bairava surya wrote:As there are totally 6 reference in the heap and three objects has assigned null
I only see four objects instantiated. Can you show us in code, where these six objects where created? Or are you confusing objects and references?
I see Beta objects created on lines 13 and 14, and two Alpha objects created on 15 and 16. Regardless of what objects become available for GC, where do you see two additional objects created that might be?
bairava surya wrote:can anyone help me with the problem?
It is probably a good idea to separate the idea of objects and references. Once you do that, you will be able to connect the references to the objects.
As mentioned, there are four objects. Mark them on paper (in a diagram), and don't use the references to mark them, because that can change.
There are actually seven references. Four are local variables. Two are instance variables. And one is a static variable. You also have to remember that in the case of the static variable, you don't actually need an instance to access it.
So, is that enough ideas for you to draw out what is reachable or not?
bairava surya wrote:tel me the exact reason how one object is eligible for garabage collection and what about remaining objects?
bairava, you are asking the impossible (which seems to be a trend).
Most gc's these days are almost certainly heuristic-based algorithms based on "current statistics", so even if you knew what it was based on, you'd be hard-pressed to predict how it's going to work.
And I would appreciate it if you "asked" questions rather than "demanding" answers. This is now the third time I've posted about this, and frankly, I'm getting tired of it. If you don't feel willing to conform to our guidelines, then find another site.
If I see any further violations of the HowToAskQuestionsOnJavaRanch guidelines, I shall ask my colleagues to suspend your account.
As a side note, in my opinion, in terms of difficulty, this seems to be one of the easier GC reachability questions encountered. I would recommend that the OP, use some paper and a pencil, and work it though (as previously recommended) -- as you are going to be encountering more difficult cases later.