• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

object references in a method GCed??

 
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

options: //1
//2
//3
//4
Never
Ans : Never
Ok I agree with the answer that whenver an object is passed inside a method's argument cannot be GCed.
Hence 'a' will never be garbage collected.
but does that mean all the refrences of 'a' i.e
'b' and 'c' also can never be Gced??
Sonir
 
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sohir,
Object references are never garbage collected. The object that is referenced by the reference can be gc'ed.
This might be a little bit confusing...Have a look at following.

However, b and c are not gc'ed. the object created at line 1 can be gc'ed. Reference is just like a gateway to memory location which can be gc'ed. the scope of a reference var ends after the scope of block.
HIH
Rashmi
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the call were done like getObject(new Object()) this object would be eligable for g.c. after line 3.
Thus I think the question is not very well worded.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic