Originally posted by Matt DeLacey:
It has been said that local variables become eligible for garbage collection when they go out of scope. This sort of implies that there aren't eligible before then, but what happens if they are set to null before they go out of scope. Would they then be eligible for gc BEFORE they went out of scope?
Matt
Originally posted by Ajith Kallambella:
Good notes Kavitha. !!
Sorry for being picky, but I would just like to comment on two of your statements -
[b]First of all, garbage collection is vendor specific & is run as the lowest priority thread by the JVM (which is again vendor specific). Since its run as the lowest priority thread, one can't predict when gc will be run. It is normally run when there are no more threads ready for execution.
This is usually true, however because of the vendor dependency, it is better not to make any assumptions. There may be implementations of VM where GC is made a priority thread - VMs running on hardware where memory is very expensive, hand-held devices and PDAs for example. So let's just say GC is vendor specific and you cannot assume anything about the priority of the GC thread.
Second point to remember is automatic variables are gc'd when they go out of scope.
I would like to correct this statement and say, automatic variables become eligible for garbage collection when they go out of scope.
You can be assured you will not get very tricky questions about GC in the exam. The typical questions will be identifying when the object becomes eligible for garbage collection
Just my two cents worth ....
Ajith[/B]
Originally posted by Amit Saini:
Hi all,
i=expr;
-the value of the expr is assigned to i;
-now the assignment operator is at the last of precedence table
therefore whatever be the expression, the value of that expression will be assigned to i, as the last step of evaluation.
-now let us dissect the expression>
i=0;
i=i++;
the value of i comes out to be 0 as we all know.
this is how it all works.
++ has higher precedence.
i++ will increment the value of i but u see since it is a post increment operator the initial value of i i.e 0 is somehow magically stored in the expression..
i=(i++) as i=(0); //note i is incremented to 1
now , the final evaluation is:
i=0; // even at this moment i was 1;
but after the exec. of the above statement i becomes 0;
i hope it is clear