• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

garbage collection

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
The objects those have no more reference or set to null are garbage collected.
Is there any specific rule for String objects which are created by new String statement to be garbage collected.Because it creates two objects one in the heap and one in the pool.
And how the String LITERALS are garbage collected.
Someone please explain.
Thank you.
mita
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mita,
The objects that are new'ed, are created on the Heap and are garbage collected using the 'zero reference' rule. This is an important concept for SCJP, so make sure you understand it well.
The objects created in the String pool are not subjected to GC until the class is unloaded by the JVM. They get discarded at the time, or just before the virtual machine unloads the class bytecode. For the purpose of the SCJP exam, you are not required to know the details of String pool memory management.
Hope this helps,
Ajith
 
mita
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ajith, I appreciate it.
mita
 
My name is Inigo Montoya, you killed my father, prepare to read a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic