1. A property added to a DOM object is a reference to an object. Example:
var MyObject = {};
document.getElementById (' Mydiv '). MyProp = MyObject;
Workaround:
Write in the Window.onunload event: document.getElementById (' mydiv '). MyProp = null;
2, Dom objects and JS objects to reference each other. Example:
function Encapsulator (Element) {
This.elementreference = element;
Element.myprop = this;
}
New Encapsulator (document.getElementById (' mydiv '));
Workaround:
Write in the OnUnload event: document.getElementById (' mydiv '). MyProp = null;
3, to the DOM object with Attachevent binding events. Example:
function DoClick () {}
Element.attachevent ("onclick", DoClick);
Workaround:
In the OnUnload event, write: Element.detachevent (' onclick ', doclick);
4, from outside to inside the execution appendchild. At this point, even if the call RemoveChild can not be released. Example:
var parentdiv = document.createelement ("div");
var childdiv = document.createelement ("div");
Document.body.appendChild (PARENTDIV);
Parentdiv.appendchild (CHILDDIV);
Workaround:
Perform appendchild from inside to outside:
var parentdiv = document.createelement ("div");
var childdiv = document.createelement ("div");
Parentdiv.appendchild (CHILDDIV);
Document.body.appendChild (PARENTDIV);
5. Rewriting the same property over and over again will result in large memory consumption (but the memory will be released after the IE is closed). Example:
for (i = 0; i < 5000; i++) {
Hostelement.text = "ASDFASDFASDF";
}
This approach is equivalent to defining 5,000 attributes!
Workaround:
In fact, there is no solution: p~~~ is the programming time to avoid this situation slightly ~ ~
Description
1, the above data are from Microsoft's official MSDN site, link address:
Http://msdn.microsoft.com/librar ... e_leak_patterns.asp
You can go to the address above to see the detailed instructions, including examples and legends are there. Just my English is not very good, see not quite understand, if I mentioned above have mistakes or need to add places please point out.
2, for the first article, in fact, including Element.onclick = Funcref This type of writing is also included, because this is also a reference to the object. Should be released when the page is onunload.
3, for the third article, in the MSDN instructions in English, it seems that even if the call DetachEvent can not release memory, because in the attachevent has caused the memory "leak", but after the detachevent situation will be better. Do not know whether this is the case, please good English parents can point out.
4, in the actual programming, these memory problems of the actual impact is not, especially for customers to use, customers will not be aware of this, but these problems for programmers is always a heart---have such a bug in mind always feel uncomfortable? It is best to solve the problem. In fact, I am in webfx.eae.net such a top-level JS source site, in their source code will see the above solution to the release of memory management.
When studying JSVM, we found that the GC () method was defined in Js.lang.System.
System.GC = function ()
{
if (System.isiebrowser ())
{
CollectGarbage ();
SetTimeout ("CollectGarbage ();", 1);
}
}
CollectGarbage () is an IE-specific release memory function