Suggest an editImprove this articleRefine the answer for “What does the cleanup function inside effect() do?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)**The cleanup function** inside `effect()` is a way to remove or stop something before the effect's next run. Angular calls it automatically before the effect fires again or when the effect is destroyed. **Key point:** cleanup is needed so that old subscriptions, timers, and other side effects do not pile up across repeated runs of the effect.Shown above the full answer for quick recall.Answer (EN)ImageThe cleanup function inside `effect()` is a way to **remove or stop** something before the effect's next run. Angular calls it automatically **before the effect fires again** or **when the effect is destroyed**. ### Example: ```ts import { signal, effect } from '@angular/core'; const id = signal(1); effect(onCleanup => { const timer = setInterval(() => { console.log('ID:', id()); }, 1000); onCleanup(() => clearInterval(timer)); // cleanup before the next run }); ``` ### What happens: 1. The effect runs and creates a `setInterval`. 2. When `id` changes, Angular calls the cleanup function (`clearInterval`) so two timers do not run at once. 3. Then it runs the effect again. **Summary:** cleanup is needed so that old subscriptions, timers, and other side effects do not pile up across repeated runs of the effect.For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.