[Greasemonkey] Re: GM & FF memory leaks?

John Plsek jplsek at iinet.net.au
Thu Feb 9 19:37:12 EST 2006


that code looks familiar ;-) ... I think I understand your changes
Andre wrote:
> I only found the EventManager somewhere as an example and fixed one bug.
>
> The idea is that any code you want to execute triggered by an event is 
> registered using e.g.
>
>     EventManager.Add(trigger, "click",  myOnclick,  false);
>
> The Eventmanager keeps track of them all and registers its own unload 
> event. Before the next page gets loaded or this page gets refreshed, 
> an 'unload' event is triggered and the Eventmanager.CleanUp routine 
> removes all Listeners by calling removeEventListener. Supposedly this 
> should help against the memory leaks. I am not sure whether it really 
> helps.
Not so sure in greasemonkey 0.5.x or 0.6.x, but it made (at least to the 
scripts I wrote it for) a big difference back in the days of 0.3.x (and 
the short lived 0.4.x)
>
> Jeremy Dunck wrote:
>>
>> EventManager is designed singleton-ish, so no need to instantiate it.
>>
>> You do need to initialize it, though.
>> Include his code, then call this:
>> EventManager.Initialise();
>
>
> Actually it initializes itself on the first call:
>       Add: function(obj, type, fn, useCapture) {
>         this.Initialise();
>         ...
>
>>
>> Then use it as he described:
>> EventManager.Add(trigger, "click",  myOnclick,  false);
>>
>> But you'll still want to clean up on unload:
>> window.addEventListener('unload', 
>> function(){EventManager.CleanUp();}, false);
>
> Not really. On the first call (in Initialise()) it registers an 
> 'unload' EventListern with
>     EventManager.Add(window, "_unload", this.CleanUp);
>
>>
>> .... He's got a special case for unload vs. _unload; I'm not sure what
>> that's about.
>
> '_unload' is its own unload event listener that really gets 
> registered. All the others from user code are named 'unload' and will 
> be stored in the EventManger registry only in order to be called in 
> 'CleanUp()'. They will not be registered in an addEventListener call, 
> because there would be no guarantee, that they are called exactly 
> once. In the original code they might get called twice.
>
> Andre
>
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey at mozdev.org
> http://mozdev.org/mailman/listinfo/greasemonkey
>


More information about the Greasemonkey mailing list