Back to articles
RxJS in Angular — Chapter 2 | Subscribe & Unsubscribe — The Secret to No Memory Leaks

RxJS in Angular — Chapter 2 | Subscribe & Unsubscribe — The Secret to No Memory Leaks

via Dev.to JavaScriptJack Pritom Soren

Subscribe & Unsubscribe — The Secret to No Memory Leaks Newsletter Series: RxJS Deep Dive for Angular Developers Written so clearly, even a 5th grader can understand it. 👋 Welcome Back! In Chapter 1, we learned that an Observable is like a water pipe — and subscribe() is how you open the tap to receive data. But here's the thing nobody tells beginners: If you forget to CLOSE the tap, water keeps flowing forever — even after you leave the room. In code, that's called a memory leak . 💧 And it's one of the most common bugs in Angular apps. Today we're going deep into subscribe() — how it works, all its options, and the right way to unsubscribe to keep your app healthy. 🔁 Quick Recap from Chapter 1 // Open the tap — start receiving data this . userService . getUsers (). subscribe (( users ) => { this . users = users ; }); Simple. But what happens when the component is destroyed ? The subscription is still alive! Like a leaking tap 💧 🧠 Understanding Subscriptions — The Full Picture When you

Continue reading on Dev.to JavaScript

Opens in a new tab

Read Full Article
2 views

Related Articles