This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Garbage collection

 
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