ts-alan
ts-alan

Reputation: 39

Do I have to unsubscribe from completed observable in rxjs?

If an observable completes, do I still have to unsubscribe / dispose (in RxJS) the observable to remove the Observer (prevent memory leaks) or is this handled internally by Rxjs once a onComplete or onError event occurs?

Upvotes: 3

Views: 1125

Answers (1)

edwin
edwin

Reputation: 2821

No, you don't need to unsubscribe from an observable you know has completed.

If you look at the source code of the RxJS toPromise() function, you'll see a subscribe, but no unsubscribe. That's because it is not necessary, you know the observable is completed.

Upvotes: 5

Related Questions