tags:

views:

66

answers:

1

I have following queries regarding java string pool:

  1. Is it a part of java heap of is it a part of native heap of JVM?.As per my understanding its the first one.

  2. Do we have any limit on the size of this string pool?Or is it user configurable ?

  3. In the following two statement

    String str = "Stack";
    String str2 = str.concat("overflow");
    

As per my understanding first string literal will be part of the string pool,but after that i did concat on the same string pool object,and it will create new string object,so will this object be allocated in the string pool or it will be in the java heap outside string pool?

4 . I am assuming that the string pool size is fixed,then what happens if this string pool get fully occupied?Do gc will clean up string pool?or JVM can expand the string pool size?

+1  A: 

In the current Sun/Oracle implementation interned strings will be in the permanent generation of the Java heap, along with class data. There is no separate memory area for strings.

The maximum size of this area is configurable with a command line option (-XX:MaxPermGen or something).

Generally concat will create a new String object allocated as any other.

If the PermGen fills up, then you get an OutOfMemoryError. GC typically runs on the PermGen, but less frequently.

All this is subject to change between implementations and versions.

Tom Hawtin - tackline