File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes String Pool and GC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "String Pool and GC" Watch "String Pool and GC" New topic

String Pool and GC

Gary Marshall
Ranch Hand

Joined: Feb 19, 2007
Posts: 122
consider this code:

When this method completes, will the entry in the String Pool for "abc" remain or does it get deleted from the String Pool? If it remains, then when will it go away? Perhaps when the program ends? When the JVM stops running?

Thank you

Javin Paul
Ranch Hand

Joined: Oct 15, 2010
Posts: 295

Hi Gary,

Yes , "abc" will remain in String Pool even after this method gets completed and I beleive it only be removed when program gets terminated , Since String pool is gets created in Perm area of Java heap , it potentially exposes the chance of OutOfMemory in Perm space with huge string literal , anybody disagree ?


SQL Query Interview Question java67 Javarevisited
Bert Bates

Joined: Oct 14, 2002
Posts: 8898
On the real exam, objects of type String will never be used in a GC question.

Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

+ For more details, have a look on this

|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Ram Narayan.M
Ranch Hand

Joined: Jul 11, 2010
Posts: 247

Since JVM maintains this String Constant Pool, when we end up the JVM process, String constant Pool will be "removed"...

SCJP 6 [SCJP - Old is Gold]
I agree. Here's the link:
subject: String Pool and GC
jQuery in Action, 3rd edition