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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 60050
    
  65

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: 19541
    
  16

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

Joined: Oct 13, 2005
Posts: 36478
    
  16
The reference will point to null until either it goes out of scope, or you reassign it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Object Reference
 
Similar Threads
k&b book chapter 3 -exercise 2 - clarification needed
Garbage Collection of Strings and Objects
aString;equals(bString) on null-object
Declaration of Static variables - code standard
Question on Boxing