Cleanup unused Event.cache entries
Reported by Michael M Slusarz | July 29th, 2008 @ 11:54 PM | in 1.6.1
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 July 29th, 2008 @ 11:58 PM
Whoops - additional patch to correct some typos in the original patch.
-
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 July 30th, 2008 @ 06:29 AM
- → Assigned user changed from to John-David Dalton
- → Milestone changed from to 1.6.1
- → State changed from new to enhancement
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():
http://prototype.lighthouseapp.com/projects/8886/tickets/245-add-object-isempty
if (Object.isEmpty(c)) delete cache[id]; -
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).
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
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.
