Fixed
Status Update
Comments
il...@google.com <il...@google.com> #2
Yigit, do you have time to fix it?
reemission of the same liveData is racy
reemission of the same liveData is racy
sa...@google.com <sa...@google.com>
il...@google.com <il...@google.com> #4
Thanks for the detailed analysis. This may not be an issue anymore since we've started using Main.immediate there but I' not sure; I'll try to create a test case.
pr...@google.com <pr...@google.com> #5
just emitting same live data reproduces the issue.
@Test
fun raceTest() {
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData)
emitSource(subLiveData) //crashes
}
subject.addObserver().apply {
testScope.advanceUntilIdle()
}
}
@Test
fun raceTest() {
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData)
emitSource(subLiveData) //crashes
}
subject.addObserver().apply {
testScope.advanceUntilIdle()
}
}
ph...@gmail.com <ph...@gmail.com> #6
With 2.2.0-alpha04 (that use Main.immediate), the issue seems to be still there (I tested it by calling emitSource() twice, like your test case)
Description
Component used: androidx.lifecycle:lifecycle-viewmodel
Version used: 2.6.1
Devices/Android versions reproduced on: n/a
Current implementation of
addCloseable
doesn't have a check ofmCleared
, unlike ofputTagIfAbsent
. It may lead to memory leaks, because user can not add check ofmCleared
and close Closeable by its own. For example, if we start background task (thread, coroutine, rx-java chain), it is possible for this task to be active afteronClear
invocation (even this time is small) and add Closeable object afteronClear
. In this case,Closeable.close()
will not be invoked.Could be this check added to
addCloseable
implementation?