src/share/classes/java/util/WeakHashMap.java

Print this page

        

*** 88,98 **** * should be taken to ensure that value objects do not strongly refer to their * own keys, either directly or indirectly, since that will prevent the keys * from being discarded. Note that a value object may refer indirectly to its * key via the <tt>WeakHashMap</tt> itself; that is, a value object may * strongly refer to some other key object whose associated value object, in ! * turn, strongly refers to the key of the first value object. One way * to deal with this is to wrap values themselves within * <tt>WeakReferences</tt> before * inserting, as in: <tt>m.put(key, new WeakReference(value))</tt>, * and then unwrapping upon each <tt>get</tt>. * --- 88,99 ---- * should be taken to ensure that value objects do not strongly refer to their * own keys, either directly or indirectly, since that will prevent the keys * from being discarded. Note that a value object may refer indirectly to its * key via the <tt>WeakHashMap</tt> itself; that is, a value object may * strongly refer to some other key object whose associated value object, in ! * turn, strongly refers to the key of the first value object. If the values ! * in the map do not rely on the map holding strong references to them, one way * to deal with this is to wrap values themselves within * <tt>WeakReferences</tt> before * inserting, as in: <tt>m.put(key, new WeakReference(value))</tt>, * and then unwrapping upon each <tt>get</tt>. *