Hi all, I've added WeakHashMap to WTF in https://commits.webkit.org/r278803, which allows the use of WeakPtr as keys. Like WeakHashSet, WeakHashMap does not immediately delete the key or the value when the object pointed by WeakPtr goes away (i.e. WeakPtrImpl::m_ptr becomes nullptr).
Instead, it relies on rehashing and amortized deletion to remove these entries. This happens either when enough items are inserted or removed such that the underlying HashMap goes through rehashing or when WeakHashMap's entry is accessed (get, find, advancing an iterator, etc...) or mutation (inserting, removing, etc...) more than twice the number of items in the underlying HashMap. Due to this amortized deletion behavior, there is no unbound growth of HashMap even if no attempt to cleanup null WeakPtr is made. However, if WeakHashMap is never accessed or mutated, all WeakPtrImpl as well as the corresponding hash map values will be kept alive. In the situation where this is undesirable (e.g. WeakHashMap could retain a large object as its values or a large number of keys could become stale), call WeakHashMap::nullReferences() to trigger the cleanup manually. - R. Niwa
_______________________________________________ webkit-dev mailing list webkit-dev@lists.webkit.org https://lists.webkit.org/mailman/listinfo/webkit-dev