• Post Reply Bookmark Topic Watch Topic
  • New Topic
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 ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

garbage collection for String

 
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody ,
How Strings are garbage collected ?

Thanks & regards,
S
 
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The same as every other object, once there are no more references to that object, it becomes eligible for garbage collection, I put that in bold because is doesn't guarantee that it will be collected, only that it could be collected.

Hunter
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and i believe String literals, which are in the string pool, are never collected.
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

fred rosenberger wrote:and i believe String literals, which are in the string pool, are never collected.


right, but the references to those literals can be collected. Sorry I shouldve mentioned that, thanks Fred.

Hunter
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hunter McMillen wrote:right, but the references to those literals can be collected. Sorry I shouldve mentioned that, thanks Fred.


No, the garbage collector only deals with objects. Variables (references to objects) are not objects themselves; the garbage collector doesn't clean up those.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When people discuss String GC and memory the following comes to mind.
Might be worth while reading this.
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4513622
 
S Majumder
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Hunter McMillen for your reply.
Actually we know that strings are located on the String constant pool , so after calling the GC what is happened ?

regards,
S


 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

s begri wrote:we know that strings are located on the String constant pool


Only string literals and interned strings are located in the string pool. As Fred said these are not garbage collected. All other string objects are located in normal heap memory and are garbage collected the same way as other objects
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joanne Neal wrote:Only string literals and interned strings are located in the string pool.


actually the references of the string literals and interned strings are located in the string pool. always String objects are live in heap. and those references never removed by JVM, thus the objects which referenced by string constant pool are not eligible for Garbage Collection.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Seetharaman Venkatasamy wrote:

Joanne Neal wrote:Only string literals and interned strings are located in the string pool.


actually the references of the string literals and interned strings are located in the string pool.


Indeed. Thanks for clarifying that.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic