Hot vs Cold Observables
No. Documentation is the safest bet. Also, I disagree with @martin's comment, it absolutely does matter. You need to be careful with cold observables to avoid resubscribing and reissuing expensive operations (e.g. by using multicasting or saving off the result to a subject).
You also have to rely on the documentation to know when/how an observable completes. For example, you don't need to ever worry about unsubscribing from HttpClient.post
because you know it will complete. However, if you're using some kind of wrapper around HttpClient which serves requests via a cached Subject you might not complete anymore. Every component will generate a new subscription and, after the component is destroyed, that subscription will be a reference from the Subject to the component so the component won't be garbage collected and you will end up with a memory leak.
There is no way to programmatically know what kind of Observable you've subscribed to, whether it will complete or not.
In general this is managed both by being smart about completing your observables and by using tools like takeUntil
or Subscription
to clean up subscriptions to long running non-completing observables or expensive observable workloads.
*EDIT: Actually, to clarify, you need to be careful with all observables, not just cold observables. Hot observables can generate expensive workloads too.
*EDIT2: Update example removing ActivatedRoute as those observables are completed when the component is destroyed.