Recall & Review
beginner
What is a memory leak in Angular applications?
A memory leak happens when the app keeps using memory for things it no longer needs, like leftover subscriptions. This can slow down or crash the app over time.
Click to reveal answer
beginner
Why should you unsubscribe from Observables in Angular?
Unsubscribing stops the app from listening to data streams that are no longer needed. This frees memory and prevents memory leaks.
Click to reveal answer
beginner
Name a common Angular lifecycle hook used to unsubscribe from Observables.
The ngOnDestroy lifecycle hook is used to clean up subscriptions before the component is destroyed.
Click to reveal answer
intermediate
What is the purpose of the 'takeUntil' operator in Angular RxJS?
The 'takeUntil' operator automatically unsubscribes from an Observable when another Observable emits a value, often used with a 'destroy' notifier to clean up subscriptions.
Click to reveal answer
intermediate
How can using the async pipe in Angular templates help prevent memory leaks?
The async pipe automatically subscribes and unsubscribes from Observables when the component loads and unloads, so you don't have to manage subscriptions manually.
Click to reveal answer
What happens if you don't unsubscribe from an Observable in Angular?
✗ Incorrect
If you don't unsubscribe, the subscription stays active and can cause memory leaks.
Which Angular lifecycle hook is best for unsubscribing from Observables?
✗ Incorrect
ngOnDestroy is called just before the component is removed, making it ideal for cleanup like unsubscribing.
What does the 'takeUntil' operator do in RxJS?
✗ Incorrect
'takeUntil' unsubscribes from the source Observable when the notifier Observable emits.
How does the async pipe help with memory management?
✗ Incorrect
The async pipe handles subscription and unsubscription automatically, preventing leaks.
Which of these is NOT a good practice to avoid memory leaks in Angular?
✗ Incorrect
Keeping subscriptions active forever causes memory leaks and should be avoided.
Explain why unsubscribing from Observables is important in Angular and how you can do it.
Think about what happens when components are removed and how to clean up.
You got /4 concepts.
Describe three methods to prevent memory leaks caused by subscriptions in Angular.
Consider lifecycle hooks, template tools, and RxJS operators.
You got /3 concepts.