Home  >  Article  >  Web Front-end  >  Example tutorial on how js objects and dom objects refer to each other

Example tutorial on how js objects and dom objects refer to each other

零下一度
零下一度Original
2017-06-27 15:10:091496browse

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 for

anonymous 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 JS object and the JS object and the JS object and the leak of JS memory leaked by the editor DOM objects refer to each other. I hope it helps everyone. If you have any questions, please leave me a message. The editor will reply to you in time! ###

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn