brain
10/07/2019, 8:45 PMkarelpeeters
10/07/2019, 9:14 PMbrain
10/07/2019, 11:10 PMstreetsofboston
10/08/2019, 1:55 AMSystem.gc()
statements in there to strongly suggest the GC cleans up some memory.
If the out-of-memory still happens (or the heap won't settle to a value), something seems to be really wrong with the garbage collector.
For Single<T>; if you capture non-static context in its chain, be sure to unsubscribe/dispose/cancel any subsdcription to it. If not, you may leak the lambdas.brain
10/09/2019, 3:29 PMSystem.gc()
, which did not help the garbage collector collect the lambdas. We use the Android WorkManager with RxWorker in our app, which should handle disposing the reactive streams for us. I attempted explicitly releasing the disposables from our reactive streams, which also did not help.streetsofboston
10/09/2019, 3:39 PMbrain
10/09/2019, 5:14 PMprivate fun waitForThing(desiredThing: String? = null): Single<Boolean> {
var disposable: Disposable? = null
return Single.create { emitter: SingleEmitter<Boolean> ->
disposable = currentThing.subscribeBy(
onNext = { currentConnectedThing: String ->
if (desiredThing == currentConnectedThing) {
emitter.onSuccess(true)
} else if (desiredThing == null && currentConnectedThing != "Unknown") {
emitter.onSuccess(true)
}
})
}.timeout(30, TimeUnit.SECONDS)
.onErrorReturnItem(false)
.doFinally {
disposable?.dispose()
}
}
Having the Single emitter referenced in another subscription seemed to cause the whole chain to leak.