takeUntil subscription still retaining observers after component teardown — diagnosis needed
0 reputation · 08 Feb 2021, 18:30 UTC
Symptom
I have an Angular component that subscribes to a long-lived observable (an interval-based stream) and uses takeUntil with a dedicated Subject that emits in ngOnDestroy. The intent is that destroying the component releases the subscription and everything it references.
The uncertainty is whether this pattern alone guarantees teardown in my setup. The same destroy subject is also passed to a second subscription, and the source stream is wrapped in shareReplay without an explicit refCount configuration. I am unsure whether a shared takeUntil notifier can cause premature or incomplete unsubscription, or whether shareReplay keeps an internal subscription alive even after all downstream observers unsubscribe.
Assume RxJS 7.x and a current Angular LTS. I plan to verify with repeated mount/destroy cycles and heap snapshots in Chrome DevTools, comparing retained size against a version without takeUntil.
- Does
shareReplaywithoutrefCount: trueretain the source subscription after the lasttakeUntil-terminated subscriber unsubscribes? - Is sharing one destroy subject across multiple subscriptions a documented risk for premature unsubscription?
- Which heap-snapshot signature (e.g., retained Subscriber or ReplaySubject instances) best confirms the leak source?