In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you about the memory release problems that need to be paid attention to in JS programming under IE. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.
And everyone focus on IE JS programming to pay attention to the memory release problem, in IE JS programming, the following programming methods will cause the problem that even if IE is closed, the memory can not be released, the following classification is given.
Memory release problems that should be paid attention to in IE JS programming
In JS programming under IE, the following programming methods will cause the problem that memory cannot be freed even if IE is turned off, which is classified below.
1. The property added to the DOM object is a reference to an object.
Example:
VarMyObject= {}; document.getElementById ('myDiv'). MyProp=MyObject
Solution:
Write: document.getElementById ('myDiv') .myProp=null in the _ window.onunload event
2. DOM object and JS object refer to each other.
Example:
FunctionEncapsulator (element) {this.elementReference=element; element.myProp=this;} newEncapsulator (document.getElementById ('myDiv'))
Solution:
Write: document.getElementById ('myDiv'). MyProp=null in the onunload event
3. Bind events to the DOM object with attachEvent.
Example:
FunctiondoClick () {} element.attachEvent ("onclick", doClick)
Solution:
Write: element.detachEvent ('onclick',doClick) in the onunload event
4. Execute appendChild from outside to inside. At this point, even if removeChild is called, it cannot be released.
Example:
VarparentDiv=document.createElement ("div"); varchildDiv=document.createElement ("div"); document.body.appendChild (parentDiv); parentDiv.appendChild (childDiv)
Solution:
Perform appendChild from the inside out:
VarparentDiv=document.createElement ("div"); varchildDiv=document.createElement ("div"); parentDiv.appendChild (childDiv); document.body.appendChild (parentDiv)
5. Rewriting the same property repeatedly will cause a large amount of memory consumption (but memory will be freed when IE is closed).
Example:
For (iSuppli)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.