Garbage collection on interned strings, String Pool and perm-space

After studying the internal elements of java strings, I was embarrassed by what is called "perm space". Initially, I realized that it contained String literals, as well as class metadata, as described in this question .

I also read about the String.intern() method and put String in a string pool, returning a link to a unique instance. I understand that this is the same string pool that stores String literals that exist in the real JVM space. It did not seem to me that the β€œperm space” could be modifiable (it is, after all, constant, right?). But then I found this question where the top voted EJP comment from the accepted answer explains that

Inner strings have been GC-capable for several years.

Assuming that the GC runs on a perm space that doesn't seem very constant. How is this reconciled? Does GC check everything in perm space? Does GC check everything in the string pool, including string literals from the source? Is there a second row pool for inner rows? Does the Civil Code know just to look at internships during the collection? Or is this comment flawed and interns a string that prevents it from ever being GC'd (in my opinion, it is not)?

+7
java garbage-collection string jvm string-interning
Aug 09 '13 at 17:40
source share
1 answer

String literals are interned . Starting with Java 7 , the JVM HotSpot puts interned strings in a heap, not permgen.

Prior to java 7, hotspot puts interned strings in perm. However, the interned strings in the partition collected garbage . Apparently class objects in permgen can also be assembled , so everything in permgen can be assembled, although the assembly of permissions may not be enabled by default in some older JVMs.

String literals, being interned, will be the link contained in the declaration of the class object to the String object in the pool. Thus, the interned literal string will be collected only if the object of the class that referred to it was also assembled.

+7
Aug 09 '13 at 18:46
source share



All Articles