WeakKeyArrayMap
A pure-Kotlin common WeakMap implementation using WeakRef.
Keys are compared using equals.
This implementation is ideal when caching requests that are relatively cheap or when the keys have short lifetimes: we prefer to free memory early.
Performance characteristics
Elements are stored in an ArrayList. On each operation, elements are scanned linearly until the element on which the operation is requested is found. Expired elements are freed when they are visited. This implies that all operations are in O(n)
.
Additionally, older elements are visited more often, so they are more likely to be freed early.