These are chat archives for ReactiveX/RxJava

23rd
Jul 2018
David Stocking
@dmstocking
Jul 23 2018 19:25
If I don't dispose of a TestObserver does it just stick around in memory until all my unit tests end? For some odd reason, I stumbled across dispose and though "Why am I not calling this?" and couldn't come up with a reason. Does anyone else do this? I couldn't find any examples that disposed of TestObserver.
David Karnok
@akarnokd
Jul 23 2018 21:17
It depends on what you test and how. JUnit test classes are "renewed" so even if you have instance fields of TestObservers, they will get GCd just like method-local ones. However, if you leave an async flow hanging that is rooted in one of the standard schedulers, you may get a leak. So if your test terminates a TestObserver, you don't have to dispose it. If your test quits without getting a terminal event, you should dispose the TestObserver.
David Stocking
@dmstocking
Jul 23 2018 21:34
Thanks @akarnokd. I guess it makes sense that if you use a TestScheduler local to the test you will still get GCed. I think it is probably best if I add an explicit dispose for these async tests. Besides leaking memory, I think I could possibly have an Observable triggered from another test before the GC has run. I do not want to flakiness in my test.