jQuery in Action, 2nd edition*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes gc from msterexam Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "gc from msterexam" Watch "gc from msterexam" New topic
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
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

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
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: gc from msterexam
 
Similar Threads
GC of objects inside Collection
stack vs heap
Garbage Collection of static variables
garbage collection?
GC Question from Exam Cram Page 163