How does the JavaScript engine handle memory leaks?
Instruction: Explain the concept of memory leaks in JavaScript and how they are dealt with.
Context: This question tests the candidate's knowledge of memory management and garbage collection in JavaScript.
Updated
Official answer available
Read the opening below, then unlock the full answer and practical guidance.
An engine can reclaim unreachable managed objects, but it cannot know that a reachable object is no longer useful to the application. A leak commonly occurs when an unintended reference keeps obsolete data reachable. Garbage collection does not repair that ownership mistake.
Examples include an unbounded cache, an interval closure retaining a large model, or a listener on a long-lived target retaining a removed component...