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

Object Reference  RSS feed

 
pammi rao
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once an object is up for garbage collection what happens to the object reference?Does the memory allocated to the reference be freed or will it just be set to null. What happens after its set to null?
Thank you
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An object that has a reference is not eligible for garbage collection.
 
pammi rao
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will first make my reference null and then the object is up for garbage collection.Now will the reference sit there untill eternity holding a null value.?
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:An object that has a reference is not eligible for garbage collection.

Except when it's part of an island of isolation - a set of objects that together cannot be reached from a live thread. An example is a List of elements; even though the List still has references to the elements, if those are the only references and the List is eligible for garbage collection, so are these elements.
 
Campbell Ritchie
Marshal
Posts: 55722
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reference will point to null until either it goes out of scope, or you reassign it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!