Two Laptop Bag
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Immutability ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Immutability ?" Watch "Immutability ?" New topic

Immutability ?

Sirish Kumar Gongal Reddy
Ranch Hand

Joined: Oct 25, 2004
Posts: 109
1)My Question is Strings are immutable objects right?means we can't modify the object why because string is adding into stringpool every time we declare a new string if and if there is no string with the same name other wise it create one new reference for our string.that's why we can't chage the string.
2)Grabagecollector will not work on stringpool right?

Now my Question is who is going to reclaim the memory of stringpool on the heap ?

G Sirish Reddy.,
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
Question is why to reclaim the string pool memory? I don't see the point to do this.

SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
Sravan Kumar
Ranch Hand

Joined: Sep 11, 2005
Posts: 121
Whether garbage collectors collect objects in a string pool is implementation dependent. It is highly unlikely that a question on garbage collection of string pool literals appears in the exam. As far as the exam is concerned, please be sure that any object (even Strings) for which there are no live references will be garbage collected.

keep smilin :: sravan<br /><a href="" target="_blank" rel="nofollow">I scribble here</a>
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
"coffee", please read our JavaRanch Naming Policy and change your displayed name to comply with it. We require a name in the format <first name><space><family name>, preferably your real name. After a few more posts, your profile will be disabled if you continue without changing your displayed name.

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Sirish Kumar Gongal Reddy
Ranch Hand

Joined: Oct 25, 2004
Posts: 109
Let me thank first for you answeres.Guys so far my Question is not cleared.
As per language specification GrabageCollector won't invoke in Stringpool for to clear unused string objects.My Question is who is going to clean those String objects ?
G Sirish Reddy.,
Sandeep Chhabra
Ranch Hand

Joined: Aug 28, 2005
Posts: 340
I think OS would reclaim the memory as soon as JVM ends.
although not sure..


Regards<br />Sandy<br />[SCJP 5.0 - 75%]<br />[SCWCD 1.4 - 85%]<br />------------------<br />Tiger, Tiger burning bright,<br />Like a geek who works all night,<br />What new-fangled bit or byte,<br />Could ease the hacker's weary plight?
I agree. Here's the link:
subject: Immutability ?
It's not a secret anymore!