min
07/19/2026, 8:30 AMfun clearKey(key: Any?) {
val entry = entries[key] ?: return
entry.isDisposable = true
if (entry.isDisposable && entry.refCount <= 0) {
remove(key)
}
}
public override fun onCleared() {
entries.toScatterMap().forEachValue { entry ->
entry.isDisposable = true
if (entry.refCount <= 0) {
remove(entry.key)
}
}
}
What’s the difference between entry.isDisposable && entry.refCount <= 0 and entry.refCount <= 0?min
07/19/2026, 8:32 AMTofu Cat
07/20/2026, 12:46 PMentry.isDisposable = true
if (entry.isDisposable && entry.refCount <= 0) {
remove(key)
}
appears to be a very redundant check on entry.isDisposable , so both expressions should probably be
entry.refCount <= 0 only.Bhaskar
07/27/2026, 6:16 PMTofu Cat
07/27/2026, 6:44 PMbut in multi-threaded environment these double checks become essential to safeguard before removal of key.I'm trying to spin in my head how that would be a valid safety check in that context.
entry.isDisposable = true
if (entry.isDisposable
&& // <-- Couldn't a mutation happen here on `isDisposable`?
entry.refCount <= 0) {
remove(key)
}
I'd tend to believe it is either very redundant or very unreliable way of achieving safety, but I am very new to Android ecosystem and Kotlin in general, so maybe there's something I'm missing?