This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

eligible for garbage collection  RSS feed

 
rex tony
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


i can't understand any can explain this concepts?
Regards
Rex
 
Pranav Bhatt
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rex,
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...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!