0
0
Angularframework~5 mins

Unsubscribing and memory leaks in Angular - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AThe Observable stops emitting data.
BThe app will automatically unsubscribe for you.
CMemory leaks can occur because subscriptions stay active.
DNothing, it's safe to ignore.
Which Angular lifecycle hook is best for unsubscribing from Observables?
AngAfterViewInit
BngOnDestroy
CngOnInit
DngDoCheck
What does the 'takeUntil' operator do in RxJS?
AUnsubscribes when another Observable emits
BConverts Observable to Promise
CDelays the Observable emissions
DStarts a new Observable
How does the async pipe help with memory management?
AIt automatically unsubscribes when the component is destroyed
BIt caches data permanently
CIt prevents Observables from emitting
DIt delays subscription until user clicks
Which of these is NOT a good practice to avoid memory leaks in Angular?
AUnsubscribe manually in ngOnDestroy
BUse takeUntil with a destroy notifier
CUse async pipe in templates
DKeep subscriptions active forever
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.