jQuery in Action, 3rd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes eligible for garbage collection 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 "eligible for garbage collection" Watch "eligible for garbage collection" New topic

eligible for garbage collection

rex tony
Ranch Hand

Joined: Aug 29, 2007
Posts: 159

i can't understand any can explain this concepts?
Pranav Bhatt
Ranch Hand

Joined: Mar 20, 2006
Posts: 284
Here first at the time of creation
a refers to Integer object i.e a-> Integer Object
b refers to Long object i.e b-> Long Object
c refers to String object i.e a-> Sting Object

We will go now line by line-:

Line 4-: a-> null, so Integer Object is not being referenced by any references.

Line 5-: a refers to what c is refering
i.e a->String Object , c->String Object , b-> Long Object

Line 6-: c refers what b is refering so-:
c-> Long Object, b-> Long Object ,a-> still String Object

Line 7-: b refers to what a is refering so finally we land at
a-> String Object, b-> String Object and c-> Long Object

So only our Interger object has lost references to it. So eligible to GC.
I hope this clears it...
I agree. Here's the link: http://aspose.com/file-tools
subject: eligible for garbage collection
jQuery in Action, 3rd edition