• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

GC String

 
Ranch Hand
Posts: 380
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Sample 1 here : on Line 3 there will be no object that is Gc'ed where as in line 3 of Sample 2 there is One object that is Gc'ed/
Reason : In Sample 1 the string created is kept in the JVM pool - and hence not destroyed when referances to it are removed.

Please confirm by thinking,.






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

I Think this is true that String Objects created in pool are never Garbage Collected, Whereas String Objects created by new keyword are created on heap and are Garbage Collected.
 
author
Posts: 9034
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

This is an interesting topic and at the same time it has the distinction of NOT being on the exam. In their infinite wisdom, the exam creators graciously decided not to mix String objects in with garbage collection questions.

So, when you're studying up for GC questions, don't worry about the string constant pool! GC questions will use other kinds of objects!

hth,

Bert
 
Sandeep Chhabra
Ranch Hand
Posts: 340
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Can Same thing be said about




???
[ September 24, 2005: Message edited by: Sandeep Chhabra ]
 
Bert Bates
author
Posts: 9034
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sandeep,

This is a valid question to study for the exam! Do you think there is any difference between the two examples when you use wrapper objects?

- Bert
 
What is that? Is that a mongol hoarde? Can we fend them off with this tiny ad?
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic