No, typically you can not "destroy reference from String pool in Java" manually.

The main reason I suppose why you are targeting it is to avoid out of memory errors. In Java 6 days all interned strings were stored in the PermGen – the fixed size part of heap mainly used for storing loaded classes and string pool. Besides explicitly interned strings, PermGen string pool also contained all literal strings earlier used in your program. The biggest issue with string pool in Java 6 was its location – the PermGen. PermGen has a fixed size and can not be expanded at runtime. You can set it using -XX:MaxPermSize=N option. This would lead to memory leaks and out of memory errors.

In Java 7 – the string pool was relocated to the heap. It means that you are no longer limited by a separate fixed size memory area. All strings are now located in the heap, as most of other ordinary objects.

You may also increase the string pool size by configuring -XX:StringTableSize=N. If you are not sure about the string pool usage, try -XX:+PrintStringTableStatistics JVM argument. It will print you the string pool usage when your program terminates.

In JDK, there is also a tool named jmap which can be used to find out number of interned strings in your application.

jmap -heap process_id

Eg:

jmap -heap 18974

Along with other output, this command also outputs number of interned strings and the space they occupy "xxxxxx interned Strings occupying xxxxxx bytes."

The rules for garbage collection of objects in the String pool are the same as for other Strings or any other object. But the fact that the String objects that correspond to String literals mostly are always reachable since there is an implicit reference to the string object in the code of every method that uses the literal and so typically they are not candidates for garbage collection. However, this is not always the case. If the literal was defined in a class that was dynamically loaded (e.g. using Class.forName(...)), then it is possible to arrange that the class is unloaded. If that happens, then the String object for the literal will be unreachable, and will be reclaimed when the heap containing the interned String gets GC'ed.

Answer from Robin Rizvi on Stack Overflow
🌐
Quora
quora.com › How-can-I-remove-the-objects-from-the-String-constant-pool-in-Java
How to remove the objects from the String constant pool in Java - Quora
Answer (1 of 4): > No You can’t. How is the pool managed? Main characteristics: * String literals are stored in the pool * Interned strings are stored in the pool ([code ]new String("abc").intern();[/code]) * When a string [code ]S[/code] is interned (because it is a literal or because [cod...
🌐
Coderanch
coderanch.com › t › 617337 › java › manually-delete-object-String-constant
How to manually delete an object from String constant pool ? (Java in General forum at Coderanch)
Now, if you wrote a cache, would you want clients to be able to clear it, or remove objects from it, any time they want? Winston · "Leadership is nature's way of removing morons from the productive flow" - Dogbert Articles by Winston can be found here ... Winston, you are right. I finally got the answer (after researching all this time) that the only time objects get deleted from the String constant pool is when the class gets unloaded.
Discussions

java - How to clear the entry from String Literal Pool - Stack Overflow
Possible Duplicate: Garbage collection behaviour for String.intern() How does Java store Strings and how does substring work internally? According to me the String reference when declared as... More on stackoverflow.com
🌐 stackoverflow.com
May 24, 2017
java - String Constant Pool - Stack Overflow
As explained in these Stackoverflow questions: question 1 & question 2 I understand that "String literals" are interned when: String s = "abc"; And that the JVM will create a new String object More on stackoverflow.com
🌐 stackoverflow.com
String constant pool
First, if you're preparing, check out www.bekli.it there are, um, more than 2000 questions - for free - covering the ocjp. Next, to confirm your stance: String x = "Cat"; String y = "Cat"; String z = new String("Cat"); System.out.println("x == y :"+(x==y)); System.out.println("x == z :"+(x==z)); Which will print "true" and then "false". But of course you didn't ask that, you asked what happens when you do a new String("Cat"); Ok, think about it like this - what if you wrote String x; String y = new String(x="Cat"); (Also, you can write this). Well, you'd probably tell me that first the "Cat" is put in the string pool, and then the y is created in the heap, with the chars in "Cat". Which would be correct. This is, of course, identical to what happens when we just write String y = new String("Cat"); Yes? More on reddit.com
🌐 r/learnjava
4
1
July 10, 2018
Java - String & constant pool - Stack Overflow
This is more like a utility class to work on that char sequence. This char sequence is maintained in following variable: /** The value is used for character storage. */ private final char value[]; When you create the String with new keyword like this ... then Object is created into the Heap Memory , and when Java Compiler encounters any String literal , It creates one Object inside constant pool... More on stackoverflow.com
🌐 stackoverflow.com
Top answer
1 of 1
10

No, typically you can not "destroy reference from String pool in Java" manually.

The main reason I suppose why you are targeting it is to avoid out of memory errors. In Java 6 days all interned strings were stored in the PermGen – the fixed size part of heap mainly used for storing loaded classes and string pool. Besides explicitly interned strings, PermGen string pool also contained all literal strings earlier used in your program. The biggest issue with string pool in Java 6 was its location – the PermGen. PermGen has a fixed size and can not be expanded at runtime. You can set it using -XX:MaxPermSize=N option. This would lead to memory leaks and out of memory errors.

In Java 7 – the string pool was relocated to the heap. It means that you are no longer limited by a separate fixed size memory area. All strings are now located in the heap, as most of other ordinary objects.

You may also increase the string pool size by configuring -XX:StringTableSize=N. If you are not sure about the string pool usage, try -XX:+PrintStringTableStatistics JVM argument. It will print you the string pool usage when your program terminates.

In JDK, there is also a tool named jmap which can be used to find out number of interned strings in your application.

jmap -heap process_id

Eg:

jmap -heap 18974

Along with other output, this command also outputs number of interned strings and the space they occupy "xxxxxx interned Strings occupying xxxxxx bytes."

The rules for garbage collection of objects in the String pool are the same as for other Strings or any other object. But the fact that the String objects that correspond to String literals mostly are always reachable since there is an implicit reference to the string object in the code of every method that uses the literal and so typically they are not candidates for garbage collection. However, this is not always the case. If the literal was defined in a class that was dynamically loaded (e.g. using Class.forName(...)), then it is possible to arrange that the class is unloaded. If that happens, then the String object for the literal will be unreachable, and will be reclaimed when the heap containing the interned String gets GC'ed.

🌐
Coderanch
coderanch.com › t › 327742 › java › remove-strings-String-constant-pool
How to remove strings from String constant pool ? (Java in General forum at Coderanch)
I've heard, however, that modern ... is a garbage collected environment, you cannot destroy any objects. However, you can make objects available for garbage collection, including string constants....
🌐
Baeldung
baeldung.com › home › java › java string › guide to java string pool
Guide to Java String Pool | Baeldung
August 20, 2025 - From Java 7 onwards, the Java String Pool is stored in the Heap space, which is garbage collected by the JVM. The advantage of this approach is the reduced risk of OutOfMemory error because unreferenced Strings will be removed from the pool, thereby releasing memory.
🌐
GeeksforGeeks
geeksforgeeks.org › java › string-constant-pool-in-java
String Constant Pool in Java - GeeksforGeeks
October 28, 2025 - Using the new keyword forces the JVM to create new objects in the heap outside the String Constant Pool, even if an identical value already exists there. Hence, s1 and s2 refer to different heap objects. When a string is created, Java determines how to allocate memory based on its declaration type:
Find elsewhere
🌐
Study.com
study.com › business courses › business 104: information systems and computer applications
Java String Constant Pool: Concept & Mechanism - Lesson | Study.com
October 12, 2018 - String literals are immutable. This means they do not change. Yes, you can re-assign a new string literal value to employee2. However, Java has still stored 'Edgar Allen Poe' in the string constant pool. This doesn't go away.
🌐
Medium
antony-s-smirnov.medium.com › java-string-pool-594f19b1bb58
Java String Pool.. A Java String pool refers to a… | by Anton Smirnov | Medium
February 25, 2024 - However, there’s a caveat: String objects are immutable, meaning there are no methods defined to change (overwrite) or clear the contents of a String object after use. This characteristic makes String objects unsuitable for storing sensitive ...
🌐
Edureka
edureka.co › blog › java-string-pool
What is String Pool in Java | String Pool Examples | Edureka
June 6, 2023 - After learning the concept theoretically, let me tell you how does a String pool work in Java step by step with the help of simple instances! Discover the power of Flutter and learn how to leverage its features in a Flutter Development Course. ... JVM automatically checks if the same value exists in the string constant pool or not.
🌐
Java Guides
javaguides.net › 2018 › 07 › guide-to-java-string-constant-pool.html
Java String Constant Pool
March 25, 2025 - In Java, the String Constant Pool (also called the String Intern Pool) is a special memory area in the Java Heap that stores string literals. It’s a memory optimization technique that avoids creating duplicate String objects with the same value. ... ➡️ Java doesn’t create a new object — it simply points str2 to the same "Java" instance in the pool.
Top answer
1 of 5
33

Maybe this will aid your understanding:

String literal = "test";
String one = new String(literal);
String two = "test";

System.out.println(literal == two); //true
System.out.println(one == two); //false

In the example you posted:

String one = new String("test");
String two = "test";

the reference passed to the constructor String(String) has the same value as the reference two due to interning. However, the string itself (referenced by these two references) is used to construct a new object which is assigned to reference one.

In this example, there are exactly two Strings created with the value "test": the one maintained in the constant pool and referenced whenever you use the literal "test" in an expression, and the second one created by the "new" operator and assigned to the reference one.

Edit

Perhaps you're confused about this statement:

When the compiler encounters a String literal, it checks the pool to see if an identical String already exists.

Note that this might be more clearly stated as:

When the compiler encounters a String literal, it checks to see if an identical String already exists in the pool.

Strings are only put in the pool when they are interned explicitly or by the class's use of a literal. So if you have, for example, this scenario:

String te = "te";
String st = "st";

String test = new String(te) + new String(st);

then while a String will exist with the value test, said String will not exist in the pool as the literal "test" has never occurred.

2 of 5
8
    //Creates a new object even if one exists in the pool
    String s1 = new String("Tendulkar");

    // makes a new object string and then the reference is available to the pool
    String s2 = s1.intern();

    //this object is not created but references the address present in the pool
    String s3 = "Tendulkar";

    System.out.print(s1==s2); // results in false
    System.out.print(s2==s3); //very very true !!!
🌐
Javatpoint
javatpoint.com › string-pool-in-java
String Pool in Java - Javatpoint
March 17, 2014 - String Pool in Java with java tutorial, features, history, variables, object, programs, operators, oops concept, array, string, map, math, methods, examples etc.
🌐
Reddit
reddit.com › r/learnjava › string constant pool
r/learnjava on Reddit: String constant pool
July 10, 2018 -

I am preparing for the OCA Java 8 exam and I am confused in regards to strings and what happens when they're created. I understand that Strings are created in one of two methods: by "new" keyword and by String literals. When created by String literals, Java first looks inside the String constant pool to see if there are any matching Strings, if non are available then a new String object is created and a reference to it is returned. When created by the "new" keyword a new String object is created in the non pool heap. Both String objects are not related even if both String objects have the same characters. I hope I have this concept correct. My question is, when creating a String object by means of the "new" keyword, does the String object's created by the "new" keyword String literal go inside the String constant pool and becomes available for reuse or those it permanently stay outside the pool? I feel that because it's created in the non pool heap and because you can create Strings using both methods and both objects won't equal to be the same but rather point to different references, Strings created using the "new" keyword will create a non pool String and the String stays outside the pool and cannot be use by any other reference variable?

🌐
DEV Community
dev.to › tishaag098 › string-constant-pool-storage-of-strings-1784
String Constant Pool (Storage of Strings) - DEV Community
February 14, 2022 - A string constant pool is a separate place in the heap memory where the values of all the strings...
🌐
Smartprogramming
smartprogramming.in › tutorials › java › string-constant-pool
String Constant Pool in Java - Memory Management Explained
But objects in the String Constant Pool (SCP) are treated specially: Even if no reference is pointing to the string literal, it is not garbage collected immediately. It usually stays in memory until the JVM itself shuts down. This is because literals are reused by the JVM to save memory. ... Since string literals are reused from SCP, memory usage is reduced and performance is improved compared to creating new objects every time. The intern() method in Java is used for memory optimization.
🌐
Scaler
scaler.com › home › topics › java › string pool in java
String Pool in Java - Scaler Topics
February 27, 2022 - Whenever a string literal is created, the JVM first checks the String Constant Pool before creating a new String object corresponding to it. Let us first discuss the memory allocation methods used in Java - Stack Memory Allocation and Heap Memory Allocation.
🌐
CodingTechRoom
codingtechroom.com › question › string-constant-pool-mechanism-java
What is the String Constant Pool Mechanism in Java? - CodingTechRoom
Solution: Avoid using 'new String()' for constant strings. Use string literals instead. Mistake: Misunderstanding string interning and its impact on memory usage. Solution: Use String.intern() judiciously; while it saves memory, excessive interning can lead to memory overhead.
🌐
Coderanch
coderanch.com › t › 551334 › java › delete-String-Object-JVM-String
Can we delete a String Object from JVM String Pool? (Java in General forum at Coderanch)
September 2, 2011 - programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums · this forum made possible by our volunteer staff, including ... ... Nope. If you don't want a String to be in the String pool, you must make sure it doesn't get put into it in the first place: don't use it as a String literal, and don't intern() it.