Bird
0
0

What will happen if you subscribe to an observable but never unsubscribe in Angular?

medium🧠 Conceptual Q5 of 15
Angular - RxJS and Observables Fundamentals
What will happen if you subscribe to an observable but never unsubscribe in Angular?
AAngular throws an error immediately.
BThe observable automatically unsubscribes after first value.
CIt may cause memory leaks by keeping subscriptions alive.
DNothing, subscriptions are managed automatically.
Step-by-Step Solution
Solution:
  1. Step 1: Understand subscription lifecycle

    Subscriptions stay active until explicitly unsubscribed or completed.
  2. Step 2: Consequences of not unsubscribing

    Active subscriptions keep resources and listeners alive, causing memory leaks.
  3. Final Answer:

    It may cause memory leaks by keeping subscriptions alive. -> Option C
  4. Quick Check:

    Subscription cleanup importance = C [OK]
Quick Trick: Always unsubscribe to avoid memory leaks. [OK]
Common Mistakes:
MISTAKES
  • Assuming automatic unsubscription
  • Believing Angular throws errors for this
  • Thinking subscriptions end after one value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes