File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes What is Weak Reference Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "What is Weak Reference " Watch "What is Weak Reference " New topic
Author

What is Weak Reference

Senthil Kumar Sekar
Ranch Hand

Joined: Aug 08, 2010
Posts: 45


Hi All,
I was going through many links on Weak Reference,Weak HashMap.
Still iam not clear.So, I have chosen this 2 way communication.
Can anybody explain me?

Thanks.

Regards
Senthil Kumar Sekar
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
There are several kinds of reference, the commonest being strong. This means that an object is always “reachable” until the reference is broken, and that object cannot be deleted by the garbage collector.
There are at least two other kinds (weak and phantom). What they mean is that the object can be garbage collected, provided it has no strong references remaining. Have you found the package summary?
It appears that objects which cease to be strongly reachable are put into a queue to be deleted; when they are removed from the queue, their memory can be reclaimed because they are no longer reachable.

I am sure other people will know more about this than me.
Siva Vulchi
Ranch Hand

Joined: Nov 17, 2011
Posts: 30
Basically Weak References are one way of controlling object's garbage collection.

When an object is only reachable through Weak reference (which means object is neither strongly reachable nor softly reachable), then it becomes eligible for GC. During the run of GC, this object will be marked and garbage collected.

In case of WeakHashMap, keys are referenced through Weak references. When a key is not being used or it is not strongly reachable, then in next run of GC, these keys will be garbage collected and hence mapping entry will be removed from the hashmap.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is Weak Reference
 
Similar Threads
HashTable
What is Weak Object Reference?
weak references
Garbage Collection Question
Java's Garbage Collection