Do I need to unsubscribe from observables, which completes / eliminates errors?

When I know that the observable will certainly complete (either with a complete notification or error ) before my component / class goes out of scope, do I still need to unsubscribe to prevent memory leak? In other words, the error that is observed automatically is completed / fixed, so I do not need to worry?

+13
source share
1 answer

The Signing and Unsubscribing section of the Supervised Contract is final regarding your subject. It states:

When an Observable issues an OnError or OnComplete notification to its observers, it ends the subscription. Observers do not need to send a notification of unsubscription to complete a subscription that ends with Observed in this way.

This is also mentioned in the Observable Termination section:

When an Observable issues an OnError or OnComplete notification to its observers, it ends the subscription.

So no, there is no need to unsubscribe from observables that are final or erroneous. However, there is no harm in this.

+17
source

Source: https://habr.com/ru/post/1013528/


All Articles