Front-end memory leak The memory usage is high, causing the page to freeze and no response after a click. A memory leak is a failure to release memory that is no longer needed by system processes.

In the global variable browser, the global object is the Window object. Variables are not released until the window closes or the page is refreshed. If undeclared variables cache a large amount of data, memory leaks can occur.

Function fn(){a = ‘global test’} function fn(){a = ‘global test’} Fn () copy code solution: 1. Avoid creating global variables

2. In strict mode, add use strict to the top of the js file header or function

Why closures cause memory leaks: Closures can read variables inside functions and then keep those variables in memory at all times. If local variables are not cleaned up at the end of use, memory leaks can result.

Solution to uncleaned DOM element references: Manually delete them

elements.btn = null

Lebyte forgotten timer or callback solution: Manually delete timer and DOM

RemoveEventlistener Removes event listening

ES6 prevents memory leakage weakMap data structure, WeakMap() const ele = document.getelementById (‘example’) wm.set(element,’something’) Wm. Get (Element ** PS: need to learn video focus B station BV1Wh411a75X? p=3&spm_id_from=pageDriver