• 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

 
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).]
 
Morning came much too soon and it brought along a friend named Margarita Hangover, and a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic