• 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

Garbage Collection question

 
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At what point is the object CREATED AT LINE 05 available for garbage collection.



Select most appropriate answer
a) At line 5
b) At line 7
c) At line 8
d) At line 10
e) At line 9
f) At line 12

My doubt is the answer option d or e is correct. Kindly help.
When the control comes to execute line 09,the anObj object reference started to point to new object SAMPLE.So I am asking is the answer e is correct.
[ September 27, 2006: Message edited by: Shiva Mohan ]
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
E looks good to me. At that point, your variable would be referring to a new object since Strings are immutable.

Chris
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"E" appears to be the right answer for me too.
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
since the strings are immutable thats why a new object is created by this line
anObj = anObj.UpperString();

but my question is control cannot go back ...
only when the obj is assigned null then only it is valid entry for the GC..

please can anyone explain me..

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

if the object has no references from any live thread,then it is eligible for the garbage collection.

when
anObj = anObj.toUpperCase();
is executed a new string object will be created and the reference anObj is pointing to it.But the old string doesn't have any references assigned to it. so it is eligible for garbage collection.
 
reply
    Bookmark Topic Watch Topic
  • New Topic