Weak Object References

What is Weak Object References?

Questions by sateeshm1

Showing Answers 1 - 6 of 6 Answers

Weak reference objects are those which do not prevent their references from being made finalizable, finalized, and then reclaimed by garbage collection. This means that the object referred to by the weak reference can be garbage collected. But, if the object has a strong reference, it cannot be garbage collected.

  Was this answer useful?  Yes

bkishore2k1

  • Mar 12th, 2009
 

A weak reference is one that does not prevent the referenced object from being garbage collected. You might use them to manage a HashMap to look up a cache of objects. A weak reference is a reference that does not keep the object it refers to alive. A weak reference is not counted as a reference in garbage collection. If the object is not referred to elsewhere as well, it will be garbage collected.
Purpose: Keeps objects alive only while they’re in use (reachable) by clients.
Use: Containers that automatically delete objects no longer in use.
When GC happened: After gc determines the object is only weakly reachable
Implementing Class: java.lang.ref.WeakReference, java.util.WeakHashMap

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions