The moose likes Beginning Java and the fly likes Object Reference Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Object Reference" Watch "Object Reference" New topic
Author

Object Reference

pammi rao
Greenhorn

Joined: Feb 24, 2010
Posts: 7
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 opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50691

An object that has a reference is not eligible for garbage collection.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
pammi rao
Greenhorn

Joined: Feb 24, 2010
Posts: 7
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
Saloon Keeper

Joined: Oct 27, 2005
Posts: 18365

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.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 26710
The reference will point to null until either it goes out of scope, or you reassign it.
 
 
subject: Object Reference
 
Threads others viewed
aString;equals(bString) on null-object
Garbage Collection of Strings and Objects
Question on Boxing
k&b book chapter 3 -exercise 2 - clarification needed
Declaration of Static variables - code standard
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture