Difference between heap memory and row pool

What is the difference between a bunch of memory and a row pool in Java?

This link says that:

String s1 = "Hello";

String s2 = new String("Hello");

s1 indicates the location of the row pool and s2 also indicates the heap memory area.

+7
source share
2 answers

StringPool is the area that the JVM uses to avoid the excessive generation of String objects.

These objects can be “recycled”, so you can (re) use them to avoid wasting too much memory ...

Consider the following example:

String s1 = "cat";

String s2 = "cat";

String s3 = new String("cat");

JVM , , s2 "cat", ( "s1"), , s1

enter image description here

+20

String s = "Hello"; Sting s2= "Hello", s, s2. , String s = new String("Hello"); String s2 = new String("Hello"), s s2 .

+6

Source: https://habr.com/ru/post/1668088/


All Articles