// function used to remove a node, every attached
// attribute and every nested node via the same procedure
var destroy = (function(destroy){
// WebReflection IE leaks attemp!
function $destroy(node){
while(node.lastChild)
destroy(node.lastChild);
if(node.parentNode)
node.parentNode.removeChild(node);
};
return destroy = destroy.clearAttributes ?
function(node){
if(node.clearAttributes) // Hedger suggestion
node.clearAttributes();
$destroy(node);
} :
$destroy
;
})(document.createElement("script"));
// used to remove everything
function destroyAll(){
destroy(document.documentElement);
};
// used to avoid leaks when the page is refreshed
// or the url is changed
if(this.attachEvent)
attachEvent("onunload", destroyAll);
reasonable performances and apparently a reliable solution.
tested via this code:
attachEvent("onload", function(){
detachEvent("onload", arguments.callee);
for(var i = 0; i < 1000; i++){
a.push(document.body.appendChild(document.createElement("div")));
var node = a[i];
node.innerText = i;
node.obj = a[i];
node.attachEvent("onmouseover", function(){
node.obj.other1 = node;
});
node.onclick = function(){
this.obj.other2 = node;
};
};
});
The procedure is based on assumptions I did in this post about div[expando] and div.removeAttribute(expando)
Have you tried to call the element.clearAttribute();
ReplyDeleteto be honest ... no!
ReplyDeleteI though it owuldn't be able to remove non primitive attributes as well, good one!
Just FYI:
ReplyDeletehttp://www.hedgerwow.com/360/dhtml/ie6-clear-memory-leak/demo.php
Thanks.
@hedger, clearAttributes does not work with table, tbody, and some other element ... even if attributes are present, so I am mixing both ways.
ReplyDelete