This article mainly introduces the problem of solving JS memory leaks between js objects and dom objects referencing each other. Friends who need it can refer to it
This problem involves scope chain, js object and dom object referencing each other. Because foranonymous function , its scope chain contains three objects: the variable object of the anonymous function, the variable object of doTry() and the global variable object . At this time, the btn variable in the doTry function object refers to the dom object, that is, the doTry function object refers to the dom object; Then, according to the objects included in the anonymous function, the dom object's onclickàanonymous function object, anonymous function objectàdoTry function object , that is, get the dom object reference doTry(). Therefore, it is explained that mutual references exist, resulting in memory failure.
Solution: Interrupt mutual references. Two ways to solve:The above is the detailed content of Example tutorial on how js objects and dom objects refer to each other. For more information, please follow other related articles on the PHP Chinese website!