Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String Object and String literall

 
mamidi venkat
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

I have one doubt regarding the String object and String literals .where the String object and String literals are stored. In String pool i.e String table or In Heap.Both String object and String literal are eligible for the garbage collection or not ??
 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

When you say :



This goes to the String constant pool.

And when you say :



This goes to the heap, as well as to the pool.

Best of luck ...
 
Thiru Mu
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I dont think String objects are stored in the pool. It is stored only in heap.

Also String objects are eligible for garbage collection not the litterls..please correct me if i am wrong..
[ September 04, 2007: Message edited by: Thiru Mu ]
 
Collins Mbianda
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Thiru Mu !!!
You are rigth.

Find a very good article on String litterals here:
Strings, Literally
 
Gitesh Ramchandani
Ranch Hand
Posts: 274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anything that is object and "only object" will be eligible for Garbage collection.
 
Collins Mbianda
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gitesh Ramchandani:
Anything that is object and "only object" will be eligible for Garbage collection.


No !!!
String literals are objects.
Unlike most objects,they always have a reference to them from the String Literal Pool. That means that they always have a reference to them and are, therefore, not eligible for garbage collection.

Strings, Literally
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic