Prototype1.6 Event destroyCache is not solving IE6 memory leak

14 views
Skip to first unread message

Michel

unread,
Jan 17, 2008, 7:09:39 AM1/17/08
to Prototype: Core
Hi all,

I have been using prototype for a long time now, and I am very
thankful for your work.
Although, in this last release, the destroyCache is not helping in
IE6...
Dont know about your test cases, but I think this should be
considered.

I have made some modifications to call Event.stopObserving when
destroying cache and the memory leak gone away.

Mislav Marohnić

unread,
Jan 17, 2008, 6:18:14 PM1/17/08
to prototy...@googlegroups.com
On Jan 17, 2008 1:09 PM, Michel <michel...@gmail.com> wrote:

I have made some modifications to call Event.stopObserving when
destroying cache and the memory leak gone away.

Hi Michel,

If there are memory leaks, we're very interested in finding and solving them. Can you share with us how you detected the leak and what modifications you did to fix it? Thanks.

- Mislav

Michel David

unread,
Jan 18, 2008, 6:51:30 AM1/18/08
to prototy...@googlegroups.com
I attached a demo file and two prototype 1.6 files...
The fixed version was made by myself, but you can user the prototype version 1.5 that also does not have the leak.

I have added a line to the Event.createWrapper method, as follow

  function createWrapper(element, eventName, handler) {
    var id = getEventID(element);
    var c = getWrappersForEventName(id, eventName);
    if (c.pluck("handler").include(handler)) return false;

    var wrapper = function(event) {
      if (!Event || !Event.extend ||
        (event.eventName && event.eventName != eventName))
          return false;

      Event.extend(event);
      handler.call(element, event)
    };

    wrapper.element = element; // added
    wrapper.handler = handler;
    c.push(wrapper);
    return wrapper;
  }

Added an unloadCache, similar to v1.5:

  function unloadCache() {
    for (var id in cache)
      for (var eventName in cache[id]) {
        var els = cache[id][eventName];
        for (var i = 0; i < els.length; i++) {
          var wrapper = els[i];
          Event.stopObserving(wrapper.element, eventName, wrapper.handler);
        }
      }
  };

Changed the unload hook to this:
    window.attachEvent("onunload", unloadCache);
ie6leak.htm
prototype1.6.js
prototype1.6.fixed.js

Michel

unread,
Jan 27, 2008, 10:29:05 AM1/27/08
to Prototype: Core
found a ticket for this issue
http://dev.rubyonrails.org/ticket/9466

gonna attach this example too
> On Jan 17, 2008 9:18 PM, Mislav Marohnić <mislav.maroh...@gmail.com> wrote:
>
> > On Jan 17, 2008 1:09 PM, Michel <michel.da...@gmail.com> wrote:
>
> > > I have made some modifications to call Event.stopObserving when
> > > destroying cache and the memory leak gone away.
>
> > Hi Michel,
>
> > If there are memory leaks, we're very interested in finding and solving
> > them. Can you share with us how you detected the leak and what modifications
> > you did to fix it? Thanks.
>
> > - Mislav
>
>
>
> [ie6leak.htm]Start Test
>
>
>
> prototype1.6.js
> 163KDownload
>
> prototype1.6.fixed.js
> 164KDownload
Reply all
Reply to author
Forward
0 new messages