Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8286824

[lworld] WeakHashMap for value classes

XMLWordPrintable

      WeakHashMap uses WeakReference for keys, allowing it to retain only keys and values that are strongly referenced elsewhere.

      The behavior of WeakReference (or any Reference class) is not defined for value objects.

      WeakHashMap could benefit from one or modes to determine how value objects as keys should be allowed or retained.

      Four (4) behaviors are proposed for WeakHashMap to give the developer a choice:
       - SOFT - Keys that are value objects are retained until memory pressure clears soft references; then the keys that are value objects are removed automatically
       - STRONG - Keys are value objects are retained until they are explicitly removed
       - THROW - Keys that are value objects can not be put into the map; UnsupportedOperationException is thrown
       - DISCARD - Keys that are value objects are silently discarded; as if they were removed immediately without being visible

      The default is SOFT - key/values are removed when there is memory pressure.
      Entries will be removed automatically at some point, though less deterministically than with Weak references.

            rriggs Roger Riggs
            rriggs Roger Riggs
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: