Bird
0
0

What is wrong with this subscription code?

medium📝 Debug Q14 of 15
Angular - RxJS and Observables Fundamentals
What is wrong with this subscription code?
this.data$.subscribe(data => {
  this.value = data;
});
// No unsubscribe called anywhere
AIt will unsubscribe automatically
BIt will throw a syntax error
CIt will cause a memory leak if component is destroyed
DIt will not receive any data
Step-by-Step Solution
Solution:
  1. Step 1: Identify subscription management

    The code subscribes but never unsubscribes, risking resource leaks.
  2. Step 2: Understand Angular component lifecycle

    Without unsubscribing, the subscription stays active after component destruction, causing memory leaks.
  3. Final Answer:

    It will cause a memory leak if component is destroyed -> Option C
  4. Quick Check:

    Missing unsubscribe = memory leak risk [OK]
Quick Trick: Always unsubscribe to avoid memory leaks [OK]
Common Mistakes:
MISTAKES
  • Assuming Angular unsubscribes automatically
  • Thinking no data will be received
  • Confusing syntax errors with runtime issues

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes