[Greasemonkey] Possible source of memory leaks

Aaron Boodman zboogs at gmail.com
Sat Jul 9 01:13:16 EDT 2005


> Yes, it's pertinent now.  Because of the bug where removed elements
> lose their listeners, command callbacks are called with expando props.

Have you tested whether this actually occurs in 0.4? My extremely
scientific test of opening and closing lots of tabs which used
GM_registerMenuCommand showed no significant lossage in 0.4. Maybe it
was a bad test. Let me know if you see leakage because...

> Something like:
> menuitem.__cb = content-supplied-func;
> and later:
> menupopup.removeChild(menuItem);
> and later...
> menuitem.addEventListener("command", menuitem.__cb);

Note that menuitem is not only released, but no longer accessibly via
any means - even DOM traversal. Maybe this is why it's different.

> I also just happened on this bug, which nails us again:
> "calling addEventListener with a closure holding a content node leaks
> the document"
> https://bugzilla.mozilla.org/show_bug.cgi?id=241518

Again, do you have evidence of this? It's a pretty obvious pattern to
create a closure which holds a DOM node other than document, and I
usually avoid it like the plague.

> These are meaty Moz bugs, and it's starting to hurt.
> I just had to admit to a coworker that his FF ate 200MB cuz of us.   I
> imagine there are many more similarly annoyed.

I think maybe this embarassing situation with your coworker has
convinced you that there is some ongoing unwinnable battle with memory
leakage. Whereas it seems like to me that some code was introduced
somewhere around 0.3.3 which made GM start leaking documents (I don't
recall it leaking before then, and I've had similar reports from
various folks). Nothing significant has changed since then except 0.4
which is untested.

> I'm now for maintaining a content-based collapsible menu reg UI and
> getting away from content-intiated XUL altogether.  

I'd rather have some testing of the current rewrite before throwing it
away! I don't really think there is a magic bullet here. Yes, the
current version on the website leaks. We are all painfully aware of
that. But isn't the question that matters whether the current version
in CVS leaks? If so, let's fix it. I'm not convinced it will be that
hard.

-- 
Aaron


More information about the Greasemonkey mailing list