Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

gc from msterexam

 
Raju Champaklal
Ranch Hand
Posts: 521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?



 
Neha Daga
Ranch Hand
Posts: 504
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Raju Champaklal
Ranch Hand
Posts: 521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i thought stack variables go for gc would mean objects being referred by those variables
 
Ankit Garg
Sheriff
Posts: 9497
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Raju Champaklal
Ranch Hand
Posts: 521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey is this right that only when the method returns will the stack variables object will be gc....
 
Ankit Garg
Sheriff
Posts: 9497
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
got it
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic