What is the memory release problem that should be noticed in JS programming under IE?
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)