You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
override fun observe(owner: LifecycleOwner, observer: Observer<in T>) {
val observeSinceVersion = version
val wrapper = observerWrappers.getOrElse(observer, Observer {
if (!isPublish || version > observeSinceVersion) {
observer.onChanged(it)
}
})
observerWrappers.putIfAbsent(observer, wrapper)
super.observe(owner, wrapper)
}
override fun observeForever(observer: Observer<in T>) {
val observeSinceVersion = version
val wrapper = observerWrappers.getOrElse(observer, Observer {
if (!isPublish || version > observeSinceVersion) {
observer.onChanged(it)
}
})
observerWrappers.putIfAbsent(observer, wrapper)
super.observeForever(wrapper)
}
override fun removeObserver(observer: Observer<in T>) {
observerWrappers.get(observer)?.let { super.removeObserver(it) }
observerWrappers.removeIfPresent(observer)
}
When we call observeForever(), all looks good and calling removeObserver() with same Observer working as expected.
But if we call observe() and later lifecycle move to Destroyed state, system call removeObserver() with wrapped Observer, and we try to find it in observedWrappers among non-wrapped observers. Pair instances with weak references to observers just accumulated in array until livedata instance not GCed.
I don't know clear solution of this problem, suppose we can check wrapped and non-wrapped observers both when removing.
The text was updated successfully, but these errors were encountered:
Code from https://github.com/Shopify/livedata-ktx/blob/master/livedata-ktx/src/main/java/com/shopify/livedataktx/PublishLiveDataKtx.kt:
When we call
observeForever()
, all looks good and callingremoveObserver()
with sameObserver
working as expected.But if we call
observe()
and later lifecycle move to Destroyed state, system callremoveObserver()
with wrappedObserver
, and we try to find it inobservedWrappers
among non-wrapped observers. Pair instances with weak references to observers just accumulated in array until livedata instance not GCed.I don't know clear solution of this problem, suppose we can check wrapped and non-wrapped observers both when removing.
The text was updated successfully, but these errors were encountered: