0

I've seen different sources that seem to contradict on the matter, or maybe there's something I haven't understood.

For example, I could get a stream from an async request that returns a promise and then combine it with the latest values of other streams and subscribe to it to perform some action with the results. The stream will only emit once, so I can close it after the first emission.

If I create a stream, map a first() operator so that it completes after the first emitted value, and subscribe to it, do I need to unsubscribe explicitly to avoid memory leaks, or will the completion of the stream "unsubscribe" automatically?

Thank you.

mikepa88
  • 733
  • 1
  • 6
  • 20
  • 1
    Yes, you need to unsubscribe to avoid memory leaks. If you don't want to unsubscribe use `toPromise()` - this will convert observable to promise that you don't need to unsubscirbe. – Stan Oct 07 '19 at 18:02
  • Is this response not true, then ? https://stackoverflow.com/questions/40019177/immediately-unsubscribing-from-rxjs-observable – mikepa88 Oct 08 '19 at 08:41

1 Answers1

0

Yes it is good to unsubscribe as it will reduce your stack

Mufaddal Hamid
  • 281
  • 3
  • 12