I have a question about the disposal on RxJava. I found this below sentence on RxSwift document on Github.
When a sequence sends the
completedorerrorevent all internal resources that compute sequence elements will be freed.To cancel production of sequence elements and free resources immediately, call dispose on the returned subscription.
if I understand correctly the resources (observables) will be freed after they call onCompleted or onError.
So the question is, does RxJava do the same thing like RxSwift or I need to call the dispose by myself?
Yes, all associated resources will be disposed automatically. To illustrate run following test with RxJava 2:
boolean isDisposed = false;
@Test 
public void testDisposed(){
    TestObserver<Integer> to = Observable.<Integer>create(subscriber -> {
        subscriber.setDisposable(new Disposable() {
            @Override
            public boolean isDisposed() {
                return isDisposed;
            }
            @Override
            public void dispose() {
                isDisposed = true;
            }
        });
        subscriber.onComplete();
    }).test();
    to.assertComplete();
    assertTrue(isDisposed);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With