• 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 Collector

 
Ranch Hand
Posts: 1252
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey The following is the code:-





COuld anyone tell me with appropriate reasons where the Garbage Collector can collect any object....... in this code......


Early responses are awaited...........

 
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can solve these type of questions pictorially. Thats the best way represent each object with a circle , assignment statements wit a link to the object.

So in line 2 a new String object is created and it points to this object
In line 4 another string reference variable points to the object created in line 2
Now we have two links or references to the string object.

At line five only one string reference is set to null the other reference to the string object still exists and so this string object is not eligible for GC

COuld anyone tell me with appropriate reasons where the Garbage Collector can collect any object....... in this code......

Even if the two string references are set to null we can't say whether the Garbage collector will collect it, we can only say the object is eligible for GC.
[ April 28, 2006: Message edited by: Srinivasa Raghavan ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic