Skip to main content

What happens if you don't unsubscribe from subscriptions?

If you don't unsubscribe from subscriptions (Observable.subscribe) in Angular:

  1. Memory leaks
  • Subscriptions keep existing even after the component is destroyed.
  • This keeps objects in memory, increasing memory consumption over time.
  1. 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.
  1. 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 ready
Premium

A concise answer to help you respond confidently on this topic during an interview.