3

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?

ts-alan
  • 39
  • 2
  • https://stackoverflow.com/q/41334931/6680611 – cartant Oct 01 '18 at 08:33
  • 1
    Possible duplicate of [Does Subject.complete() unsubscribe all listeners?](https://stackoverflow.com/questions/40452979/does-subject-complete-unsubscribe-all-listeners) – Ntwobike Oct 01 '18 at 08:34

1 Answers1

5

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.

edwin
  • 2,643
  • 20
  • 17