| Author |
gc from msterexam
|
Raju Champaklal
Ranch Hand
Joined: Dec 10, 2009
Posts: 521
|
|
stack variables are not dealt with gc
when a stack variable goes out of scope it is eligible for gc
master exam says this senence is wring and the first one is the explaantiin for it
what does this mean ? objects created and being referred by stack variables...arent these objects availabel for gc once the var goes out of scope?
|
scjp 1.6 91%, preparing for scmad
"Time to get MAD now.. we will get even later"....by someone unknown
|
 |
Neha Daga
Ranch Hand
Joined: Oct 30, 2009
Posts: 504
|
|
I hope you know the difference between stack and heap.
objects are always created on heap not stack. Stack only have reference variables for the object and local variables. So, how can they be garbage collected?
until an object is refered by a variable on currently on stack, it is not eligible for garbage collection unless it is forming an island with others.
|
SCJP 1.6 96%
|
 |
Raju Champaklal
Ranch Hand
Joined: Dec 10, 2009
Posts: 521
|
|
|
i thought stack variables go for gc would mean objects being referred by those variables
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
Raju Champaklal wrote:i thought stack variables go for gc would mean objects being referred by those variables
No its not like that, stack is different from heap. GC is applicable only to heap. When a stack variable goes out of scope, the object referenced by it may or may not be eligible for GC, but the statement in master exam is not concerned with that...
|
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
|
 |
Raju Champaklal
Ranch Hand
Joined: Dec 10, 2009
Posts: 521
|
|
|
hey is this right that only when the method returns will the stack variables object will be gc....
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
Raju Champaklal wrote:hey is this right that only when the method returns will the stack variables object will be gc....
GC is not applicable to stack variables. The objects in the heap referenced by stack variables might be eligible for GC when method returns. The reason I used the work might is because the objects referenced by stack variables might be referenced somewhere else, so in that case they won't be eligible for GC...
|
 |
Raju Champaklal
Ranch Hand
Joined: Dec 10, 2009
Posts: 521
|
|
|
got it
|
 |
 |
|
|
subject: gc from msterexam
|
|
|