• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Garbage Collector

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"When a String object is concatenated actually a new String object is created, the previously reffered String is eligible for garbage collection. "
Why the previously refered string is eligible for garbage collection. I think when we concatanate a string, new string reference is created and the previous string remains as it is.
Plez clarify..
 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Depends on how you are doing it. For example if you had this:

Then yes, once s is concatentated with t, the original String "java" is elgible for garbage collection.
However if you did this:

or

Then no, the String "java" is not eligble for garbage collection since s still points to it. Strings are immutable, so unless you say s now equals something else, the original String referenced by s is still there and you are still able to get to it.
Bill


[This message has been edited by bill bozeman (edited January 26, 2001).]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic