Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

gc from msterexam

 
Ranch Hand
Posts: 521
  • 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?



 
Ranch Hand
Posts: 504
  • 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
  • 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
 
Sheriff
Posts: 9671
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • 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
  • 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: 9671
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
got it
 
Just the other day, I was thinking ... about this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic