File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How Unreachable Object Becomes Reachable again Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How Unreachable Object Becomes Reachable again" Watch "How Unreachable Object Becomes Reachable again" New topic
Author

How Unreachable Object Becomes Reachable again

srujankumar kundurthi
Greenhorn

Joined: Nov 29, 2009
Posts: 1
Hi to One and All


I am new to Java. I know that an Object becomes unreachable if its reference points to null. but i came to know that Unreachable Object can be Reachable again. Can Any Body Tell me how it's going to possible


Thanks in Advance
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
Welcome to the Ranch

You have been given misleading information; an object does not necessarily become unreachable if its reference is set to null. It depends whether there are any other references. Also an object can become unreachable without being set to null, for example if its only reference goes out of scope. I do not believe a truly unreachable object can become reachable again, but it is possible mistakenly to maintain references which one has forgotten about. The WeakReference and simlar classes are designed to guard against that possibility.

You have posted on an inappropriate forum, so I shall move this discussion.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
I earlier wrote: . . . I shall move this discussion.
I see somebody else moved it before I had the chance to. Thank you.
Shahid Pathan
Greenhorn

Joined: Dec 28, 2010
Posts: 23
Object is reachable only if application have at least a single reference(without null), if object does not have reference in application then it wont possible to make it reachable again.
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

srujankumar kundurthi wrote:
I am new to Java. I know that an Object becomes unreachable if its reference points to null.

This does not really make sense. An Object can have many references to it or non at all. Once it has no references to it, it becomes eligible for garbage collection.

If you have a variable referencing an Object and you set that variable to null then if there are no other references to it then it becomes eligible for garbage collection.


but i came to know that Unreachable Object can be Reachable again.


How did you 'came to know that Unreachable Object can be Reachable again' because it is not true. Please post your source.


Can Any Body Tell me how it's going to possible


Thanks in Advance


Edit: If I was any slower I would be answering this tomorrow!


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3432
    
  12
James Sabre wrote:How did you 'came to know that Unreachable Object can be Reachable again' because it is not true

There is one way this could happen. When an object's finalize method is called when it is about to be garbage collected, you could create a reference to it from another object. In this situation the object would no longer be garbage collected and would be reachable again.


Joanne
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
Thank you, Joanne. I forgot about the finalize() method.
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Campbell Ritchie wrote:Thank you, Joanne. I forgot about the finalize() method.


:-) That makes 2 of us!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Three


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3601
    
  14

I considered the finalize() method, but strictly speaking, at the moment finalize is called, the object is not unreachable. It's merely phantom reachable, but reachable nonetheless.

When an object is truly unreachable (after phantom references have been cleared), it will be reclaimed and there's no way to get it back.

[edit]

I guess that most texts use the term "unreachable" for objects that are eligible for garbage collection, so here unreachable is any object without a strong reference to them. Using these semantics, an object would indeed become reachable again using the finalize() method.
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3001
    
    9
The Java Language Specification would use the term "finalizer reachable" here - "phantom reachable" is a more specific concept which only applies of you're actually using a PhantomReference.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How Unreachable Object Becomes Reachable again
 
Similar Threads
garbage collection
Garbage Collection
States of the object? hum!!
garbage collection
Is this right?