aspose file tools
The moose likes Java in General and the fly likes garbage collection for String Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "garbage collection for String" Watch "garbage collection for String" New topic
Author

garbage collection for String

S Majumder
Ranch Hand

Joined: Jun 03, 2009
Posts: 241
Hi everybody ,
How Strings are garbage collected ?

Thanks & regards,
S
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 490

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


"If the facts don't fit the theory, get new facts" --Albert Einstein
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 9955
    
    6

and i believe String literals, which are in the string pool, are never collected.


Never ascribe to malice that which can be adequately explained by stupidity.
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 490

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
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12929
    
    3

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Christopher Nortje
Greenhorn

Joined: Jul 09, 2010
Posts: 16
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

Joined: Jun 03, 2009
Posts: 241
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


Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3011
    
    9
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


Joanne
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Aug 05, 2005
Posts: 3011
    
    9
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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: garbage collection for String
 
Similar Threads
Locked Thread
Tech Word Game
Default Package
WA #1.....word association
What is the least sexy occupation?