Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • They'll only be GC'd if the JVM in question is > 1.6. Prior to 1.7, all strings were stored in permgen. Commented Feb 5, 2016 at 15:15
  • 2
    @avgvstvs: “all strings were stored in permgen” is just dead wrong. Only interned strings were stored there and if they weren’t originating from string literals referenced by code, they were still garbage collected. Just think about it. If strings were generally never GCed in JVMs prior to 1.7, how could any Java application survive more than a few minutes? Commented Mar 9, 2017 at 10:28
  • @Holger This is false. Interned strings AND the String pool (pool of previously used strings) were BOTH stored in Permgen prior to 1.7. Also, See section 5.1: docs.oracle.com/javase/specs/jvms/se6/html/… The JVM always checked Strings to see if they were the same reference value, and would call String.intern() FOR YOU. The result was that every time the JVM detected identical Strings in the constant_pool or heap it would move them into permgen. And I worked on several applications with "creeping permgen" until 1.7. It was a real problem. Commented Mar 9, 2017 at 16:36
  • So to recap: Until 1.7, Strings started in the heap, when they were used they were put into the constant_pool which was located IN permgen, and then if a string was used more than once, it would be interned. Commented Mar 9, 2017 at 16:39
  • 2
    @avgvstvs: There is no “pool of previously used strings”. You are throwing entirely different things together. There is one runtime string pool containing string literals and explicitly interned string, but no other. And each class has its constant pool containing compile-time constants. These strings are automatically added to the runtime pool, but only these, not every string. Commented Mar 9, 2017 at 17:34