QUESTION: Что такое memory leaks?
Memory leaks in JavaScript represent a situation where an application continues to hold objects in RAM that are no longer needed for its operation. Over time, this leads to serious performance degradation, interface freezes, and even complete browser tab crashes.
The main reason lies in unreleased memory, when the built-in garbage collector physically cannot delete an object because active references to it still exist. A frequent cause of such problems is accidental or intentional global variables that are declared without the var, let, or const keywords, or are bound to the window object in non-strict mode. Because of this, such data lives throughout the entire lifecycle of the page.
Another common source of leaks is forgotten timers and event listeners. If you used functions like setInterval or added addEventListener to some DOM element, and then removed the element itself from the page, but forgot to call clearInterval or removeEventListener, then the callback function and the closed-over variables associated with it will remain in memory forever.
Developers should pay special attention to closures that capture DOM elements. If an inner function references a UI element, that element will not be removed from memory even after it disappears from the document tree, because the execution context continues to hold a reference to it.
For effective detection and elimination of such problems, professional developers use specialized built-in tools. A great example is the Chrome DevTools Memory panel, where you can take heap snapshots, compare their state before and after certain user actions, and find detached DOM nodes or uncleared data structures remaining in memory.