Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Garbage collection  RSS feed

 
Mubeen Shaik
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am confused with the garbage collection?. When assign "vh" reference to "s", will "v" be garbage collected?.

Please explain..


===================================


=============================

Thanks in advance,
Mubeen Shaik.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question has nothing to do with garbage collection, it relates purely to parameter passing.

As s is passed by value, outside the function the reference to v still exists.
As a result v will not be garbage collected at this point, but rather vh will be eligible for GC after the function terminates.
 
Nitin Bhagwat
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
'v' is variable. Variables can not be garbage collected.
 
Mubeen Shaik
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Thanks for that explanation. Now will "s" also be garbage collected when vh is garbage collected?.

Thanks in advance,
Mubeen Shaik.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nitin Bhagwat:
'v' is variable. Variables can not be garbage collected.


nope.
v will go out of scope when the method it is used in terminates, at which point it becomes eligible for garbage collection.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!