Skip to content

Commit

Permalink
Merge pull request knockout#856 from SteveSanderson/856-ie-attachEven…
Browse files Browse the repository at this point in the history
…t-memory-leak

Memory leak in IE 7, 8 and 9
  • Loading branch information
mbest committed Mar 15, 2013
2 parents 628816f + 16bb898 commit e2dcbc4
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,17 @@ ko.utils = (function () {
jQuery(element)['bind'](eventType, handler);
} else if (!mustUseAttachEvent && typeof element.addEventListener == "function")
element.addEventListener(eventType, handler, false);
else if (typeof element.attachEvent != "undefined")
element.attachEvent("on" + eventType, function (event) {
handler.call(element, event);
else if (typeof element.attachEvent != "undefined") {
var attachEventHandler = function (event) { handler.call(element, event); },
attachEventName = "on" + eventType;
element.attachEvent(attachEventName, attachEventHandler);

// IE does not dispose attachEvent handlers automatically (unlike with addEventListener)
// so to avoid leaks, we have to remove them manually. See bug #856
ko.utils.domNodeDisposal.addDisposeCallback(element, function() {
element.detachEvent(attachEventName, attachEventHandler);
});
else
} else
throw new Error("Browser doesn't support addEventListener or attachEvent");
},

Expand Down

0 comments on commit e2dcbc4

Please sign in to comment.