#254 enhancement
Michael M Slusarz

Cleanup unused Event.cache entries

Reported by Michael M Slusarz | July 29th, 2008 @ 11:54 PM | in 1.7

When using observe()/stopObserving() a bunch, especially on DOM elements that are removed, Event.cache eventually grows large with many entries that are no longer needed - i.e. all events for that ID no longer exist. This is a quick patch that checks for this occurrence and removes that entry.

Comments and changes to this ticket

  • Michael M Slusarz

    Michael M Slusarz July 29th, 2008 @ 11:58 PM

    Whoops - additional patch to correct some typos in the original patch.

  • John-David Dalton

    John-David Dalton July 30th, 2008 @ 06:32 AM

    Thanks for this patch.

    Can you just recompile it?

    Having to patch one then apply another patch to fix the patch just introduces

    unneeded complexity into the updating process.

    If you make a commit and then say oops I forgot something.

    You can use --amend for example:

    git add src/event.js
    git add test/unit/event_test.js
    git commit -m "delete Event.cache entries"
    // ohh crap I had a typo in it
    // ok wew, I fixed the typo
    git commit --amend test/unit/event_test.js
    <press SHIFT+Z+Z>

    But sinse it is something minor you could probably just edit the .patch file

    in wordpad or something and re-upload (you can click the little "x" next to the file to remove an upload).

  • John-David Dalton

    John-David Dalton July 30th, 2008 @ 06:29 AM

    • Assigned user set to “John-David Dalton”
    • State changed from “new” to “enhancement”
    • Milestone set to 1.7

    Your line

    if (!$H(c).values().flatten().size()) {

    Seems like a lot of work:

    convert to hash object -> iterate over all values -> flatten -> size

    It might be easier to use the proposed Object.isEmpty():


    if (Object.isEmpty(c))
      delete cache[id];
  • Juriy Zaytsev

    Juriy Zaytsev July 31st, 2008 @ 07:32 AM

    This issue was bothering me for a while.

    I think there shouldn't be any problems if we remove cache entry for an element while there's still a reference to that element.

    Next time #observe is called (and a cache is searched for element's eventId) it will be recreated again (if none exists).

    The proposed solution seems like an overkill : )

    I'm definitely in favor of isEmpty (or a simple for/in test until we implement isEmpty).

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 03:55 AM

    • Tag changed from events, tested to section:dom

    [not-tagged:"events" tagged:"section:dom" bulk edit command]

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 03:56 AM

    [not-tagged:"events" tagged:"section:dom" bulk edit command]

  • T.J. Crowder

    T.J. Crowder November 16th, 2009 @ 04:50 PM

    • Assigned user cleared.

    [responsible:none bulk edit command]

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins