GarbageCollection (GC02)
1: const element = document.getElementById('myElement');
2: const handleClick = () => {
3: console.log('Element clicked!');
4: // element.removeEventListener('click', handleClick) //<-- This must be added to prevent memory leak.
5: };
6: element.addEventListener('click', handleClick);
7:
Memory Leak (Unintentional Reference) // ... (the element might be removed from the DOM at some point) ... // Even though the element itself is removed, the reference inside `handleClick` prevents garbage collection
GarbageCollection context:
ES6 context:
- (2024) Notes about JS Closures. #ES6
- (2024) Notes about Javascript asynchronous programming. #ES6
- (2022) Modern Javascript books #ES6 #Doc
- (2021) JS learning start point #ES6
- (2021) Maximilian Schwarzmüller Javascript lecture #ES6
- (2021) Javascript interview question from Happy Rawat #ES6
- (2021) Javascript tests #ES6
- (2016) New unique features of Javascript (updated). #ES6
Comments (
)

Link to this page:
http://www.vb-net.com/JavascriptES6/GC02.htm
|