Course contentsShow
← Java
Lesson 2182 of 2,87043. String Handling in DepthFree lesson

Intern Pool Location: PermGen vs Metaspace

Understanding the evolution from PermGen (Java 7-) to heap storage (Java 7+) and its impact on pool size and GC behavior.

Intern Pool Location: PermGen vs Metaspace

You'll learn: How the physical location of the String intern pool changed across Java versions and what that means for memory management.

The Big Move

In Java 7 and earlier, the String intern pool was stored in PermGen (Permanent Generation), a fixed-size memory area separate from the main heap. This posed problems: if you interned too many strings, you'd hit an OutOfMemoryError: PermGen space, and tuning PermGen size was cumbersome.

Starting in Java 7, Oracle moved the intern pool to the main heap. In Java 8, PermGen was completely eliminated and replaced with Metaspace (which stores class metadata only, not interned strings).

Why This Matters

Before (Java 6 and earlier):

  • Pool size limited by -XX:MaxPermSize
  • Separate garbage collection rules
  • Easy to run out of space with aggressive interning

After (Java 7+):

  • Pool lives in the regular heap
  • Governed by standard heap size (-Xmx)
  • Strings can be garbage collected like any other heap object
  • Much more flexible memory management

Think of it like moving your book collection from a small, fixed closet (PermGen) to a larger, expandable library (heap) where space is shared dynamically with everything else.

Impact on Your Code

The location change is mostly transparent, but it affects:

  • GC behavior: Interned strings now participate in regular heap GC cycles
  • Memory tuning: Use heap size parameters, not PermGen settings
  • Pool size: More generous limits encourage safer use of intern()

If you're running modern Java, you benefit from this automatically—no code changes needed.

Key Takeaway:
The String intern pool moved from PermGen (Java ≤6) to the heap (Java 7+), eliminating fixed-size limits and integrating interned strings into normal garbage collection.