[Greasemonkey] Re: Memory Leaks

Andrew Murphy andrewm1986 at gmail.com
Wed Nov 9 20:09:45 EST 2005


It's large, but its at

www.guildofwisdom.co.uk/gothamore/download.asp<http://www.guildofwisdom.co.uk/gothamore/download.asp>


On 11/9/05, greasemonkey-request at mozdev.org <greasemonkey-request at mozdev.org>
wrote:
>
> Send Greasemonkey mailing list submissions to
> greasemonkey at mozdev.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://mozdev.org/mailman/listinfo/greasemonkey
> or, via email, send a message with subject or body 'help' to
> greasemonkey-request at mozdev.org
>
> You can reach the person managing the list at
> greasemonkey-owner at mozdev.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Greasemonkey digest..."
>
>
> Today's Topics:
>
> 1. Re: Roomity.com <http://Roomity.com> v 1.5 is a web 2.01 (Robert G.
> Werner)
> 2. Firefox 1.5 extension contest (Bill Donnelly)
> 3. Memory Leaks (Andrew Murphy)
> 4. Re: Memory Leaks (Andre)
> 5. Re: Memory Leaks (Lenny Domnitser)
> 6. Re: Re: Memory Leaks (Gareth Andrew)
> 7. Re: Memory Leaks (John Plsek)
> 8. Re: Memory Leaks (John Plsek)
> 9. Re: Memory Leaks (Andre)
> 10. Re: Re: Memory Leaks (Jeremy Dunck)
> 11. Re: Memory Leaks (Andre)
> 12. Re: Memory Leaks (John Plsek)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Tue, 08 Nov 2005 22:14:11 -0800
> From: "Robert G. Werner" <robert at inreachtech.net>
> Subject: Re: [Greasemonkey] Roomity.com <http://Roomity.com> v 1.5 is a
> web 2.01
> To: greasemonkey at mozdev.org
> Message-ID: <437193B3.3060008 at inreachtech.net>
> Content-Type: text/plain; charset=ISO-8859-1
>
> On 11/08/2005 6:29 PM -0800 while facing into huricane force winds
> Lenny Domnitser <ldrhcp at gmail.com> explained:
> > On 11/8/05, Jeremy Dunck <jdunck at gmail.com> wrote:
> >
> >>Feedback here:
> >>http://dunck.us/anabasis/archives/2005/11/09/roomity-bubble/
> >
> >
> > I was originally going to say "hell", but Jeremy's review got me fired
> up.
> >
> > Who the fuck wants a discussion group that they can't Greasemonkey?
> > _______________________________________________
> > Greasemonkey mailing list
> > Greasemonkey at mozdev.org
> > http://mozdev.org/mailman/listinfo/greasemonkey
> >
> I've already seen another list that got spammed with this crap. I
> think this guy is phishing for something.
>
> --
> In Reach Technology: http://www.inreachtech.net/
>
> Robert G. Werner
> robert at inreachtech.net
>
> Tel: 559.304.5122
>
> Truth has always been found to promote the best interests of mankind...
> - Percy Bysshe Shelley
>
> ------------------------------
>
> Message: 2
> Date: Wed, 09 Nov 2005 01:52:23 -0800
> From: Bill Donnelly <donnelly at snowcrest.net>
> Subject: [Greasemonkey] Firefox 1.5 extension contest
> To: Greasemonkey List <Greasemonkey at mozdev.org>
> Message-ID: <4371C6D7.80207 at snowcrest.net>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Are you going to enter Gm for 1.5 in the extension contest?
>
> http://developer.mozilla.org/contests/extendfirefox/
>
> --
> Sometimes, the most mischievous thing in the world
> you can do is to tell the simple Truth.
> -----------------------
> "There are three things extremely hard:
> steel, a diamond, and to know one's self."
> -- Benjamin Franklin, 1750 Poor Richard's Almanac
>
>
> ------------------------------
>
> Message: 3
> Date: Wed, 9 Nov 2005 12:53:49 +0000
> From: Andrew Murphy <andrewm1986 at gmail.com>
> Subject: [Greasemonkey] Memory Leaks
> To: greasemonkey at mozdev.org
> Message-ID:
> <443394370511090453r11223562ya3a4edd76315af09 at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> I have tested my script in both firefox 1.0.7 and firefox 1.5. Both give
> me
> loads and loads of memory leaks. So I assume it is either grease monkey or
> my script itself. The script is very large, in excess of 100k. Could
> anyone
> give me pointers on how to decrease the memory leaks in my script, or if
> it
> is greasemonkey/firefox itself, when they will be fixed.
>
> My memory usage can reach 200MB before firefox is so slow I have to open
> and
> close it again!
>
>
> Andrew
>
> ------------------------------
>
> Message: 4
> Date: Wed, 09 Nov 2005 14:13:35 +0100
> From: Andre <gm at andrecgn.de>
> Subject: [Greasemonkey] Re: Memory Leaks
> To: greasemonkey at mozdev.org
> Message-ID: <dkssmf$2vr$1 at sea.gmane.org>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> From: Andrew Murphy <andrewm1986 at gmail.com>
> Sent: Mittwoch, 9. November 2005 13:53:49
> Subject: Memory Leaks
> > My memory usage can reach 200MB before firefox is so slow I have to open
> and
> > close it again!
> >
>
> I have found that kicking off my script by the "onload" event creates a
> much bigger memory leak that just calling it.
>
> Fortunately, my script can run ever before the event fires, so I removed
> that call, and the memory leaks got smaller.
>
> My script is used on a page that refreshed every 2 minutes. Over night I
> have found that FF is using in excess of 500MB and stopping FF actually
> frees 800MB of memory.
>
> Andre
>
>
> ------------------------------
>
> Message: 5
> Date: Wed, 9 Nov 2005 08:18:19 -0500
> From: Lenny Domnitser <ldrhcp at gmail.com>
> Subject: Re: [Greasemonkey] Memory Leaks
> To: greasemonkey at mozdev.org
> Message-ID:
> <94355ecc0511090518q428ef35fj81b8b9651d727d40 at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> On 11/9/05, Andrew Murphy <andrewm1986 at gmail.com> wrote:
> > I have tested my script in both firefox 1.0.7 and firefox 1.5. Both give
> me
> > loads and loads of memory leaks.
>
> Show us the script.
>
> ------------------------------
>
> Message: 6
> Date: Wed, 09 Nov 2005 13:47:31 +0000
> From: Gareth Andrew <freega at freegarethandrew.org>
> Subject: Re: [Greasemonkey] Re: Memory Leaks
> To: greasemonkey at mozdev.org
> Message-ID: <1131544051.32132.20.camel at localhost.localdomain>
> Content-Type: text/plain
>
> Hi,
>
> My guess is that you are adding a new event listener every-time the
> window gets refreshed, but never removing any. If you call
> removeEventListener before you refresh do you get any improvement?
>
> Gareth.
>
> On Wed, 2005-11-09 at 14:13 +0100, Andre wrote:
> > From: Andrew Murphy <andrewm1986 at gmail.com>
> > Sent: Mittwoch, 9. November 2005 13:53:49
> > Subject: Memory Leaks
> > > My memory usage can reach 200MB before firefox is so slow I have to
> open and
> > > close it again!
> > >
> >
> > I have found that kicking off my script by the "onload" event creates a
> > much bigger memory leak that just calling it.
> >
> > Fortunately, my script can run ever before the event fires, so I removed
> > that call, and the memory leaks got smaller.
> >
> > My script is used on a page that refreshed every 2 minutes. Over night I
> > have found that FF is using in excess of 500MB and stopping FF actually
> > frees 800MB of memory.
> >
> > Andre
> >
> > _______________________________________________
> > Greasemonkey mailing list
> > Greasemonkey at mozdev.org
> > http://mozdev.org/mailman/listinfo/greasemonkey
>
>
> ------------------------------
>
> Message: 7
> Date: Thu, 10 Nov 2005 00:44:45 +1100
> From: John Plsek <jplsek at iinet.net.au>
> Subject: Re: [Greasemonkey] Memory Leaks
> To: greasemonkey at mozdev.org
> Message-ID: <4371FD4D.70905 at iinet.net.au>
> Content-Type: text/plain; charset="ISO-8859-1"
>
>
>
> ------------------------------
>
> Message: 8
> Date: Thu, 10 Nov 2005 00:46:35 +1100
> From: John Plsek <jplsek at iinet.net.au>
> Subject: Re: [Greasemonkey] Memory Leaks
> To: greasemonkey at mozdev.org
> Message-ID: <4371FDBB.7050206 at iinet.net.au>
> Content-Type: text/plain; charset="ISO-8859-1"
>
>
>
> ------------------------------
>
> Message: 9
> Date: Wed, 09 Nov 2005 15:13:32 +0100
> From: Andre <gm at andrecgn.de>
> Subject: [Greasemonkey] Re: Memory Leaks
> To: greasemonkey at mozdev.org
> Message-ID: <dkt06s$eiv$1 at sea.gmane.org>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Hi,
>
> you are right. I add several event listeners for a newly created button.
> It is a div with:
>
> var trigger = document.createElement("div");
> trigger.addEventListener("mouseover", eh_onmouseover, false);
> trigger.addEventListener("mouseout", eh_onmouseout, false);
> trigger.addEventListener("click", eh_onclick, false);
>
> How would I remove them? The refresh is done by the page, not by my code.
>
> Andre
>
> ----- Original Message -----
> From: Gareth Andrew <freega at freegarethandrew.org>
> Sent: Mittwoch, 9. November 2005 14:47:31
> Subject: Memory Leaks
> > Hi,
> >
> > My guess is that you are adding a new event listener every-time the
> > window gets refreshed, but never removing any. If you call
> > removeEventListener before you refresh do you get any improvement?
> >
> > Gareth.
> >
> > On Wed, 2005-11-09 at 14:13 +0100, Andre wrote:
> >
> >>From: Andrew Murphy <andrewm1986 at gmail.com>
> >>Sent: Mittwoch, 9. November 2005 13:53:49
> >>Subject: Memory Leaks
> >>
> >>>My memory usage can reach 200MB before firefox is so slow I have to
> open and
> >>>close it again!
> >>>
> >>
> >>I have found that kicking off my script by the "onload" event creates a
> >>much bigger memory leak that just calling it.
> >>
> >>Fortunately, my script can run ever before the event fires, so I removed
> >>that call, and the memory leaks got smaller.
> >>
> >>My script is used on a page that refreshed every 2 minutes. Over night I
> >>have found that FF is using in excess of 500MB and stopping FF actually
> >>frees 800MB of memory.
> >>
> >>Andre
> >>
> >>_______________________________________________
> >>Greasemonkey mailing list
> >>Greasemonkey at mozdev.org
> >>http://mozdev.org/mailman/listinfo/greasemonkey
>
>
> ------------------------------
>
> Message: 10
> Date: Wed, 9 Nov 2005 08:36:14 -0600
> From: Jeremy Dunck <jdunck at gmail.com>
> Subject: Re: [Greasemonkey] Re: Memory Leaks
> To: greasemonkey at mozdev.org
> Message-ID:
> <2545a92c0511090636r2d81e733ne7168ee6597a1482 at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> On 11/9/05, Andre <gm at andrecgn.de> wrote:
> > Hi,
> >
> > you are right. I add several event listeners for a newly created button.
> > It is a div with:
> >
> > var trigger = document.createElement("div");
> > trigger.addEventListener("mouseover", eh_onmouseover, false);
> > trigger.addEventListener("mouseout", eh_onmouseout, false);
> > trigger.addEventListener("click", eh_onclick, false);
> >
> > How would I remove them? The refresh is done by the page, not by my
> code.
>
> Assuming the handlers are closures over content, this is the bug in moz:
> https://bugzilla.mozilla.org/show_bug.cgi?id=241518
>
> Note that it doesn't block 1.5, but it is being actively worked.
>
> As for how to unhook them, assuming your list is static, do something like
> this:
>
> body.addEventListener("unload", unhooker, false);
>
> function unhook() {
> //get a ref to your hooked elm;
> trigger.removeEventListener("mouseover", eh_onmouseover, false);
> trigger.removeEventListener("mouseout", eh_onmouseout, false);
> trigger.removeEventListener("click", eh_onclick, false);
> }
>
> If you hooked list is dynamic, stuff gets more complicated. You'll
> need to keep your own list list of all event hooks.
>
> var hookers = {}
>
> function myAddEventListener(obj,ev,handler,cap) {
> obj.addEventListener(ev, handler, cap);
> hookers.append( { obj:obj,ev:ev,handler:handler,cap:cap} );
> }
>
> //use that instead of obj.addEventListener.
>
> then define unhook like:
> function unhook() {
> for (hooker in hookers) {
> hooker.obj.removeEventListener(hooker.ev, hooker.handler, hooker.cap);
> }
> }
>
> and hook body.unload as before.
>
> ------------------------------
>
> Message: 11
> Date: Wed, 09 Nov 2005 15:46:20 +0100
> From: Andre <gm at andrecgn.de>
> Subject: [Greasemonkey] Re: Memory Leaks
> To: greasemonkey at mozdev.org
> Message-ID: <dkt24d$kvm$1 at sea.gmane.org>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> wow, thanks!!! I should have known there is an unload event. I was
> actually searching for the list of events that you (or somebody here on
> the list) had sent around a couple of weeks ago but it was under some
> other heading.
>
> My list is static, so it is easy.
>
> Thanks, again,
> Andre
>
> ----- Original Message -----
> From: Jeremy Dunck <jdunck at gmail.com>
> Sent: Mittwoch, 9. November 2005 15:36:14
> Subject: Memory Leaks
> > On 11/9/05, Andre <gm at andrecgn.de> wrote:
> >
> >>Hi,
> >>
> >>you are right. I add several event listeners for a newly created button.
> >>It is a div with:
> >>
> >> var trigger = document.createElement("div");
> >> trigger.addEventListener("mouseover", eh_onmouseover, false);
> >> trigger.addEventListener("mouseout", eh_onmouseout, false);
> >> trigger.addEventListener("click", eh_onclick, false);
> >>
> >>How would I remove them? The refresh is done by the page, not by my
> code.
> >
> >
> > Assuming the handlers are closures over content, this is the bug in moz:
> > https://bugzilla.mozilla.org/show_bug.cgi?id=241518
> >
> > Note that it doesn't block 1.5, but it is being actively worked.
> >
> > As for how to unhook them, assuming your list is static, do something
> like this:
> >
> > body.addEventListener("unload", unhooker, false);
> >
> > function unhook() {
> > //get a ref to your hooked elm;
> > trigger.removeEventListener("mouseover", eh_onmouseover, false);
> > trigger.removeEventListener("mouseout", eh_onmouseout, false);
> > trigger.removeEventListener("click", eh_onclick, false);
> > }
> >
> > If you hooked list is dynamic, stuff gets more complicated. You'll
> > need to keep your own list list of all event hooks.
> >
> > var hookers = {}
> >
> > function myAddEventListener(obj,ev,handler,cap) {
> > obj.addEventListener(ev, handler, cap);
> > hookers.append( { obj:obj,ev:ev,handler:handler,cap:cap} );
> > }
> >
> > //use that instead of obj.addEventListener.
> >
> > then define unhook like:
> > function unhook() {
> > for (hooker in hookers) {
> > hooker.obj.removeEventListener(hooker.ev, hooker.handler, hooker.cap);
> > }
> > }
> >
> > and hook body.unload as before.
>
>
> ------------------------------
>
> Message: 12
> Date: Thu, 10 Nov 2005 02:22:28 +1100
> From: John Plsek <jplsek at iinet.net.au>
> Subject: Re: [Greasemonkey] Memory Leaks
> To: greasemonkey at mozdev.org
> Message-ID: <43721434.6060108 at iinet.net.au>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> I keep forgetting to turn html forma off!!!!!!
>
> anyway, yes, event listeners are bad ... mmmkayyy
>
> I use the following - can't recall where I got it from, but I'm 99.9999%
> sure the code was in the public domain
>
> EventManager= {
> _registry: null,
> Initialise: function() {
> if (this._registry == null) {
> this._registry = [];
> EventManager.Add(window, "_unload", this.CleanUp);
> }
> },
> Add: function(obj, type, fn, useCapture) {
> this.Initialise();
> var realType=(type=="_unload"?"unload":type);
> if (typeof obj == "string")
> obj = document.getElementById(obj);
> if (obj == null || fn == null)
> return false;
> obj.addEventListener(realType, fn, useCapture);
> this._registry.push({obj:obj, type:type, fn:fn,
> useCapture:useCapture});
> return true;
> },
> CleanUp: function() {
> for (var i = 0; i < EventManager._registry.length; i++) {
> with(EventManager._registry[i]) {
> if(type=="unload") fn();
> obj.removeEventListener(type,fn,useCapture);
> }
> }
> EventManager._registry = null;
> }
> };
>
> and, instead of (for example)
>
> element.addEventListener("click", someFunction, false);
>
> use
>
> EventManager.Add(element, "click", someFunction, false);
>
>
> J
>
> ------------------------------
>
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey at mozdev.org
> http://mozdev.org/mailman/listinfo/greasemonkey
>
>
> End of Greasemonkey Digest, Vol 12, Issue 10
> ********************************************
>


More information about the Greasemonkey mailing list