Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6824679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:55:49+00:00 2026-05-26T21:55:49+00:00

I heard that string object pool exists in the PermGC and when a string

  • 0

I heard that string object pool exists in the PermGC and when a string intern is executed, it checks the pool first to see if an equivalent string object exists, if it does not exist, it creates one and returns a reference to the pooled instance.

But here is my first question.

I think that object is created on the heap, especially in the young generation first. If it survives during few garbage collections, it moves to the old generation. can anybody explain how the string object goes to the pool that exists in the Perm GC?

second question:

String s = “test”;
s = “test1”;

If i reassign “test1” to a reference s and continue to use “test1”, does it mean that “test” (created on the young generation) will be garbage collected?

third question:
How is the string object pool related to the runtime constant pool?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:55:50+00:00Added an answer on May 26, 2026 at 9:55 pm

    What makes you think the interned String first goes to the young generation? The String#intern() method is a native method. It’s certainly very possible for an implementation to move it right into the permgen.

    Second question: if there’s no other references to that "test" String instance, it’s eligible for garbage collection. Same story if it’s interned. Even an interned String that no longer has any active references can be garbage collected. This might not have been the case in older JVMs, though. And it can be implementation-specific, I guess.

    As for the third question, I do not know. All I know is that String literals from source code are placed into the same pool. If you were to construct a String that’s equal to a String constant from source and then intern it, you’d be returned the instance that was used to represent the constant. Think of this as String literals having been interned right away.

    EDIT: just read your initial few sentences again and I think I see the reason for the confusion. When you call intern() on a String, and no equal String is in the pool yet, then it’s not first gonna construct an equivalent String. It’ll just move the instance you called intern() on to the pool rather than returning a new reference. That’s how it’s stated in the JavaDoc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've heard that using StringBuilder is faster than using string concatenation, but I'm tired
I have heard that using static member objects is not a very good practice.
I want to modify a connection string that's hard-coded in a Java application (jar
How do I avoid the same hard-coded string applicationName=membershipSampleApp that appears in multiple places
I am writing a C# application that uses a long hard-coded string. For maintainability
I heard that if you use port 443 (the port usually used for https)
I heard that you could right-shift a number by .5 instead of using Math.floor().
I heard that decision tables in relational database have been researched a lot in
I heard that Visual Studio came with an Image Library, but I can't find
I heard that on Windows you can login from a web browser to the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.