• Post Reply Bookmark Topic Watch Topic
  • New Topic

String Pool V/s Heap  RSS feed

 
Chirag Sharma
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Objects are created on the heap and Strings are no exception. So, Strings that are part of the "String Literal Pool" still live on the heap, but they have references to them from the String Literal Pool.
as mentioned on http://www.javaranch.com/journal/200409/ScjpTipLine-StringsLiterally.html

2) But I read somewhere String Literal Pool is the part of Heap and String literal created in String Literal Pool

3) Is String Constant Pool = String Literal Pool ???

which one is correct between 1 and 2 ???

Please help me out.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chirag Sharma wrote:Is String Constant Pool = String Literal Pool ???

Basically, yes; although you can augment it yourself with the intern() method. You might find the CachedObjects page useful reading.

Beyond that, I wouldn't obsess about things like "where" too much. One of the main delights of Java is that it's a memory-managed language. That means that what it does with objects, or where it keeps them, or what they look like, or how big they are, are none of your concern.

Create objects; use them; let the Garbage Collector clean them up. It's as simple as that.

Winston
 
Chirag Sharma
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Winston for reply.

But this is not exactly what that i want to know.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chirag Sharma wrote:But this is not exactly what that i want to know.

Then perhaps you should explain what you do want to know, because I thought I answered your question.

And I still say that I don't see anything in your post that a Java programmer should normally need to concern himself/herself with. It's just not important.

Winston
 
Chirag Sharma
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My Question is : What is difference b/w String Pool and Heap ??

and how they are working in case of String and normal objects??

what i want to found:
1) IS String Pool the part of Heap? // Not Sure
2) What String pool contains references, objects or values?

I think its more clear now... Please help me out.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chirag Sharma wrote:My Question is : What is difference b/w String Pool and Heap ??

They're two completely different things. The heap is where objects are created and removed from; the String pool is where String literal references are cached.

and how they are working in case of String and normal objects??

A String is a normal object. Did you read the 'CachedObjects' link I gave you?

1) IS String Pool the part of Heap?

What, like a section of it? No. But it's almost certainly an object (my guess would be a HashMap, but I'm not sure), so it will be in the heap.

2) What String pool contains references, objects or values?

The first.

However, where all this gets you, I don't know. The String pool is an implementation decision, nothing else. The language could - and quite possibly does - function perfectly well without it; for example, in micro-sized environments like cell phones (I just don't know). And it's supposed to be invisible. It's a space-saving device; nothing more.

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!