• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String Pool and GC

 
Gary Marshall
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All:
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
Gary

 
Javin Paul
Ranch Hand
Posts: 295
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ?

Thanks
Javin
 
Bert Bates
author
Sheriff
Posts: 8898
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On the real exam, objects of type String will never be used in a GC question.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
+ For more details, have a look on this
 
Ram Narayan.M
Ranch Hand
Posts: 247
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since JVM maintains this String Constant Pool, when we end up the JVM process, String constant Pool will be "removed"...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic