Try finally magical to prevent memory leaks
<div id= "D1" ></div>
<script >
function Createbutton () {
var obj = document.createelement ("button");
Obj.innerhtml= "point me!";
Obj.onclick=function () {
Handling the Click event
}
Obj.onmouseover=function () {
Handling MouseOver Events
}
Return obj;//you cannot set obj directly to NULL because the object you created needs to be returned. After return, obj is a local variable and cannot be externally disconnected from its htmlelement reference. There will be a problem leaking problem in IE
}
The var button = Document.getelementsbyid ("D1"). AppendChild (Createbutton ());
button. do something ();
button. do something ();
........
something. Certain things (buttons);
......
</script>
This type of writing in IE 100% memory leaks
It's easy to solve some problems with try finally
function Createbutton () {
var obj = document.createelement ("button");
Obj.innerhtml= "point me!";
Obj.onclick=function () {
Handling the Click event
}
Obj.onmouseover=function () {
Handling MouseOver Events
}
try{
return obj;
}finally{
obj = null;//This sentence is executed after return, which solves the problem of having the obj null after the
}
}