HuntExams Academy logo
JavaScriptAdvanced#performance#memory

What causes memory leaks in JavaScript?

Answer

Common causes are forgotten timers and event listeners, references held in global variables or module caches, detached DOM nodes still referenced by JS, and closures capturing large objects.

Example

const id = setInterval(tick, 1000);
// leak unless cleaned up
clearInterval(id);
el.removeEventListener('click', handler);

Related Interview Questions

1
JavaScriptBeginner#types

What is the difference between typeof and instanceof?

Open
2
JavaScriptIntermediate#fundamentals

What is strict mode?

Open
3
JavaScriptBeginner#fundamentals#types

What are the data types in JavaScript?

Open