This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Garbage collection 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 "Garbage collection" Watch "Garbage collection" New topic
Author

Garbage collection

Mubeen Shaik
Ranch Hand

Joined: Jan 26, 2004
Posts: 67
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.


Sun Certified Java Programmer
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
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.


42
Nitin Bhagwat
Ranch Hand

Joined: Sep 09, 2004
Posts: 132
'v' is variable. Variables can not be garbage collected.


"Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
Mubeen Shaik
Ranch Hand

Joined: Jan 26, 2004
Posts: 67
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

Joined: Oct 12, 2000
Posts: 5093
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.
 
wood burning stoves
 
subject: Garbage collection
 
Similar Threads
Marcusgreen Mock Exam1 Question 51
weird call by ref question
result doesnt match
Q51 Marcus
[inheritance]..