IdentitySoftKeyArrayMap
A pure-Kotlin common WeakMap implementation using SoftRef.
Keys are compared by identity.
This implementation is ideal when storing mappings from specific long-lived objects.
Do not use this implementation with short-lived objects! It will waste memory, as the cached values will be retained longer than necessary in case the same keys appears again, but this cannot happen since another key with the same identity cannot be created.
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.