aspose file tools
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 ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56230
    
  13

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
Sheriff

Joined: Oct 27, 2005
Posts: 19216

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: 32712
    
    4
The reference will point to null until either it goes out of scope, or you reassign it.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Object Reference
 
Similar Threads
Question on Boxing
Declaration of Static variables - code standard
Garbage Collection of Strings and Objects
aString;equals(bString) on null-object
k&b book chapter 3 -exercise 2 - clarification needed