Suggest an editImprove this articleRefine the answer for “What does ngOnDestroy() do? When is it called?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)In Angular, `ngOnDestroy()` is a lifecycle hook that is called **before a component or directive is destroyed**. **Key point:** `ngOnDestroy` is a hook for wrapping up the component's work and releasing all resources before it is removed from the DOM.Shown above the full answer for quick recall.Answer (EN)ImageIn Angular, `ngOnDestroy()` is a lifecycle hook that is called **before a component or directive is destroyed**. ## Key points 1. **What it does**: - Lets you **clean up resources** created by the component: timers, subscriptions to events (`Observable`), DOM handlers, third-party libraries. - Prevents memory leaks and unexpected errors after the component is removed. 2. **When it is called**: - **Once**, before the component is removed from the DOM. - After all view checks and updates (`AfterViewChecked`) are complete. Example: ```ts export class MyComponent implements OnDestroy { subscription: Subscription; ngOnInit() { this.subscription = this.dataService.getData().subscribe(); } ngOnDestroy() { this.subscription.unsubscribe(); // clean up the subscription console.log('Component destroyed'); } } ``` In other words, `ngOnDestroy` **is a hook for wrapping up the component's work and releasing all resources before it is removed from the DOM**.For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.