[Greasemonkey] memory leak when using DOMNodeInserted
Johnathan Conley
jconley at users.sourceforge.net
Wed Jun 28 17:27:40 EDT 2006
For some reason, my GM script causes a massive memory leak when using event
"DOMNodeInserted"
I have a complex function (called go() below) that runs when the page loads
and when it changes. The only thing it does is hides elements by setting
style.display='none' and optionally style.visibility=''
The only exception is when pass=1 (i.e. only once) a style tag is appended
to the <head> children.
The code below watches for DOMNodeInserted events and tries to only run go()
after no inserts have occurred after 200ms.
My test case is that I run this script without listening to DOMNodeInserted
and open 25 myspace pages - Firefox goes to about 320mb, and then close all
tabs - and it returns to 100mb.
When I listen to DOMNodeInserted, it stays at 320mb.
Any ideas?
var pass=0;
var change_count=0;
var notify_count=0;
var scheduled = false;
function notifyChange() {
if (notify_count==change_count)
go();
if (notify_count!=change_count) {
schedNotify();
return;
}
scheduled=false;
}
function schedNotify() {
scheduled=true;
notify_count=change_count;
setTimeout(function(e) { notifyChange(); },200);
}
go();
if (true) {
window.addEventListener("load", function(e) {
document.addEventListener("DOMNodeInserted", function(e) {
change_count++;
if (!scheduled && change_count>2)
schedNotify();
}, false);
}, false);
}
More information about the Greasemonkey
mailing list