// 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)
No comments:
Post a Comment