[Greasemonkey] GM & FF memory leaks?

Tom Van Herreweghe tomvanherreweghe at telenet.be
Tue Feb 7 22:20:46 EST 2006


I'm currently creating a userscript that implements some sort of instant 
messenger. I created some froms, and display them on the site.
The UI reloads every 3 seconds (yeah, that's quite fast). I noticed FF 
crashed a lot when the userscript was enabled.

I tried to debug it with the javascript console. I succeeded in killing 
all the bugs, except one (but that's not what's causing the leak).
I'm attaching a lot of events to the UI to check for user interaction: 
reading messages, opening/closing new windows, ...

After a good search on google, I found that "addEventListener" causes 
minor memory leaks, even on FF. I checked if it was true, and yes, 
according to the task manager, FF went from 25Mb to about 38Mb 
(gradually). I then found a replacement function to change the 
"addEventListener" in order to minimise memory leaks:

function addEvent( obj, type, fn )
{
    if (obj.addEventListener)
        obj.addEventListener( type, fn, false );
    else if (obj.attachEvent)
    {
        obj["e"+type+fn] = fn;
        obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
        obj.attachEvent( "on"+type, obj[type+fn] );
    }
}

Now, FF seemed to crash a lot slower then before, but still, it crashes. 
I checked the memory usage again, and it went from 25Mb to about 32Mb. 
The strange thing is, when only one tab is open, and I just browse the 
internet, it takes quite a long time for FF to crash. As soon as I start 
posting on a forum, or opening multiple tabs, FF crashes quite fast.

Does anyone have any idea about how to fix memory leakage for GM + FF ? 
I have searched for many days now, tried a lot of different code, ... I 
feel like making a nice project from this userscript, but right now, all 
the FF crashes make me feel depressed.

The full script can be downloaded here: 
http://hermod.encapsulated.org/wb/index.htm  (user scrip 0.3 alpha)

Thanks for your input

Tom


More information about the Greasemonkey mailing list