aspose file tools
The moose likes Beginning Java and the fly likes Object Reference Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Groovy Fundamentals video training course this week in the Groovy forum!
JavaRanch » Java Forums » Java » Beginning Java
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 ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 62817
    
  68

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by 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
Sheriff

Joined: Oct 27, 2005
Posts: 19992
    
  25

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 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 42670
    
  31
The reference will point to null until either it goes out of scope, or you reassign it.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Object Reference