Performance: onDestroy
MEDIUM IMPACT
This affects cleanup timing and memory usage after a component is removed, impacting interaction responsiveness and memory leaks.
import { onDestroy } from 'svelte'; const onResize = () => { console.log('resize'); }; window.addEventListener('resize', onResize); onDestroy(() => { window.removeEventListener('resize', onResize); });
import { onDestroy } from 'svelte'; // No cleanup of event listener window.addEventListener('resize', () => { console.log('resize'); });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No cleanup in onDestroy | No change | 0 | 0 | [X] Bad |
| Proper cleanup with onDestroy | No change | 0 | 0 | [OK] Good |