Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String pool in java 8

Tags:

java

I was reading about the memory management in java 8.It talks of Meta space but it does not talk of String pool.Can you please suggest me what happened to String pool in java 8.

Thanks in Advance. Rajesh

like image 897
Learner Avatar asked Feb 15 '17 10:02

Learner


4 Answers

The change has been done on java7 itself that the constant pool has been moved to typical heap space from permgen space(still the pool behaviour is same) where as permgen space completely removed in Java 8. Metaspace is nothing to do with constant pool specially, it is generic for all objects.

like image 74
Suresh Atta Avatar answered Oct 01 '22 04:10

Suresh Atta


Nothing is changed as in the concept of string pool but from java 7 onward string pool is created in heap memory instead of permgen. The advantage of doing this is the unreferenced variable in string pool will be taken care by JVM garbage collector. So it will improve over space.

like image 21
piyush Avatar answered Oct 01 '22 04:10

piyush


www.oracle.com/technetwork/java/javase/8-whats-new-2157071.html

here is the java 8 release notes nothing seem to be about String.intern . Here is little difference : The default value of -XX:StringTableSize parameter is 1009 in Java 6 and Java 7 until Java7u40. It was increased to 60013 in Java 7u40 (same value is used in Java 8 as well). It's subtle but gives a big performance advantage. check this blog post for more info: http://java-performance.info/string-intern-in-java-6-7-8/

like image 44
Mammad Avatar answered Oct 01 '22 02:10

Mammad


When we create a String object using the new() operator, it always creates a new object in heap memory. On the other hand, if we create an object using String literal syntax, if it already exists the Java compiler will simply return a reference to its memory address from the String pool, without allocating additional memory. Otherwise, it will create a new String object and put in the string pool for future re-use.

for more info read this :

https://www.baeldung.com/java-string-pool

like image 44
Mohamad Mirzadeh Avatar answered Oct 01 '22 02:10

Mohamad Mirzadeh