This week's book giveaway is in the Web Services forum.
We're giving away four copies of Microservices in Action and have Morgan Bruce & Paulo A. Pereira on-line!
See this thread for details.
Win a copy of Microservices in Action this week in the Web Services forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

garbage collection for String  RSS feed

 
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody ,
How Strings are garbage collected ?

Thanks & regards,
S
 
Ranch Hand
Posts: 492
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • 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: 12628
50
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • 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 Linux VI Editor
  • Mark post as helpful
  • send pies
  • 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 IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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 Java Windows XP
  • Mark post as helpful
  • send pies
  • 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
  • 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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!