Knockout never calls removeEventListener(), how does it properly remove event handlers?

328 views
Skip to first unread message

Andrew Bradley

unread,
May 16, 2012, 11:14:24 AM5/16/12
to KnockoutJS
I noticed that Knockout never removes the event listeners that it adds
to nodes. In ko.utils.registerEventHandler() it calls
addEventListener to attach the handler to the DOM node. However, in
removeNode (& cleanNode), it never makes a corresponding call to
removeEventListener().

Question:
Since these event listeners are left attached to the removed DOM
nodes, won't this potentially cause memory leaks?

Does Knockout remove event listeners in a way I'm unaware of?

Thanks,
Andrew

niraz...@gmail.com

unread,
Feb 17, 2015, 9:09:31 AM2/17/15
to knock...@googlegroups.com, cspo...@gmail.com
It's a late reply, but just for the reference:

Event handlers are automatically removed when the element is destroyed.

Once caveat is IE's proprietary (and now deprecated < 9) attachEvent, and Knockout indeed solves this issue by explicitly calling detachEvent. 

cspo...@gmail.com

unread,
Feb 17, 2015, 9:56:51 AM2/17/15
to knock...@googlegroups.com, cspo...@gmail.com, niraz...@gmail.com
Thanks for the reply; I had actually forgotten that I asked this question.
Reply all
Reply to author
Forward
0 new messages