What happens if you don't unsubscribe from subscriptions?
If you don't unsubscribe from subscriptions (Observable.subscribe) in Angular:
- Memory leaks
- Subscriptions keep existing even after the component is destroyed.
- This keeps objects in memory, increasing memory consumption over time.
- Unnecessary calls and events
- Code tied to the subscription keeps running even though the component has already been removed.
- It can cause errors if it tries to access a DOM element or component variable that no longer exists.
- Unstable application behavior
- Many active subscriptions can cause duplicated actions, unexpected renders, and slower performance.
Conclusion: you should always unsubscribe in ngOnDestroy() or use constructs like takeUntil, AsyncPipe, or Subscription.add/unsubscribe to avoid leaks and bugs.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.