Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Immutability ?

 
Sirish Kumar Gongal Reddy
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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 ?

Thanks,
G Sirish Reddy.,
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question is why to reclaim the string pool memory? I don't see the point to do this.
 
Sravan Kumar
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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.
Thanks
-Barry
 
Sirish Kumar Gongal Reddy
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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 ?
Regards,
G Sirish Reddy.,
 
Sandeep Chhabra
Ranch Hand
Posts: 340
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I think OS would reclaim the memory as soon as JVM ends.
although not sure..

Sandy
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic