Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A weak reference is a kind of reference variable which is treated specially by the garbage collector.</p> <p>This introduces another kind of reachability, any object may be:</p> <ul> <li>strongly reachable (reachable from any life thread by only <em>normal</em> references)</li> <li>weakly reachable (not strong reachable, but reachable by a weak reference (or by multiple ways, which each include a weak reference))</li> <li>not reachable at all</li> </ul> <p>(There are also <em>Soft References</em> and <em>Phantom References</em>, which I leave out here - they work similarly and introduce more levels between.)</p> <p>If an object is not reachable at all, it can be garbage-collected at any time. If an object is strongly reachable, it can not be garbage-collected at all. If the garbage collector finds that an object (or a group of objects) is weakly reachable (maybe by multiple weak references), <em>it clears all these references at once</em>, and then the objects are not reachable (and can be garbage-collected).</p> <p>(Actually there is/may be a finalization step between the "non reachable" and the collection, which also may make the object again reachable.)</p> <p>For using Weak references, you can use the class <code>java.lang.ref.WeakReference</code> - the actual reference is in a private variable of this class, and can only be set with the constructor, and later cleared. You can subclass this class, if you need other data apart from the reference itself, which should still be there when the reference is cleared.</p> <p>For an object pool in the sense of "avoid costly instantiation", a weak reference is not the right tool.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload