This project is archived and is in readonly mode.

#319 ✓resolved
Daniel Steigerwald

Fix mootools big memory leak

Reported by Daniel Steigerwald | August 15th, 2008 @ 12:46 AM | in 1.2.1

This is fix for a bug in MooTools. Events are removed only for elements contained in DOM, at time of unloading.


function createBigAssObject() {
    var o = {};
    for (var i = 0; i < 100000; ++i) { o[i] = 'blah'; }
    return o;
}

// this is fix, try to comment, and check memory after several F5
Document.implement({
    purge: function() {
        var elements = Browser.toPurge;
        for (var i = 0, l = elements.length; i < l; i++) Browser.freeMem(elements[i]);
    }
});

Browser.toPurge = [];

Native.implement([Element, Window, Document], {
    addListener: function(type, fn) {
        if (this.addEventListener) this.addEventListener(type, fn, false);
        else this.attachEvent('on' + type, fn);
        Browser.toPurge.include(this);
        return this;
    }
});
// end of the fix

window.addEvent('load', function() {
    // Create a big ass object in the local scope.
    var bigAss = createBigAssObject();
    new Element('div', {
        events: { click: function() { alert(bigAss.toString()); } }
    });
    // Because element is not in dom, MooTools ignores it, but these elements leak also!
});

Comments and changes to this ticket

  • Tom Occhino

    Tom Occhino October 3rd, 2008 @ 06:14 AM

    • Assigned user changed from “Valerio” to “Tom Occhino”
    • State changed from “new” to “resolved”
    • Milestone changed from 2.0 to 1.2.1

    fixed for 1.2.1

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

Referenced by

Pages