Bird
0
0

Why is it important to call unsubscribe() on an observable subscription in Angular?

hard🧠 Conceptual Q10 of 15
Angular - RxJS and Observables Fundamentals
Why is it important to call unsubscribe() on an observable subscription in Angular?
ATo convert the observable into a promise
BTo restart the observable from the beginning
CTo automatically complete the observable
DTo prevent memory leaks by stopping the observable when no longer needed
Step-by-Step Solution
Solution:
  1. Step 1: Understand subscription lifecycle

    Subscriptions keep listening until unsubscribed or completed, which can cause memory leaks if not stopped.
  2. Step 2: Purpose of unsubscribe

    Calling unsubscribe() stops listening and frees resources, preventing leaks.
  3. Final Answer:

    To prevent memory leaks by stopping the observable when no longer needed -> Option D
  4. Quick Check:

    Unsubscribe prevents memory leaks by stopping observables [OK]
Quick Trick: Always unsubscribe to avoid memory leaks [OK]
Common Mistakes:
MISTAKES
  • Thinking unsubscribe restarts observable
  • Confusing unsubscribe with complete
  • Believing unsubscribe converts to promise

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes