Return to Snippet

Revision: 15127
at June 25, 2009 09:34 by iTony


Initial Code
Object.protoype.purge = function purge(d) {
    var a = d.attributes, i, l, n;
    if (a) {
        l = a.length;
        for (i = 0; i < l; i += 1) {
            n = a[i].name;
            if (typeof d[n] === 'function') {
                d[n] = null;
            }
        }
    }
    a = d.childNodes;
    if (a) {
        l = a.length;
        for (i = 0; i < l; i += 1) {
            purge(d.childNodes[i]);
        }
    }
}

Initial URL
http://javascript.crockford.com/memory/leak.html

Initial Description
Memory leakage in IE6/7 if the event handlers are not purged before deleting an element.

Initial Title
Purge event handlers from a DOM element

Initial Tags
javascript, ie, DOM

Initial Language
PHP