• 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

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

Explain the below code



I thought both newestname and name both are eligible but only name is eligible for collection. Does it mean that only explicitly null assigned strings are eligible for garbage collection.

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

Originally posted by srinivas sridaragaddi:
Hi,
I thought both newestname and name both are eligible but only name is eligible for collection. Does it mean that only explicitly null assigned strings are eligible for garbage collection.

Please explain.....



Hi Srinivas,

newestName is not eligible because it has its reference pointing to the name String Object, not null. To take it a step farther, name is not eligible for GC either because it has a reference from newestName. Assigning newestName to null will make them both eligible.

Hope this helps...
Aloha,
Doug
 
I was her plaything! And so was this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic