Skip to content

Commit 9ef0299

Browse files
author
kether667
committed
fixing severe memory leak
keyup event was retaining scope which was retaining html nodes, cleaning up on $destroy verified that this fixes memory leak this article gave me insight into the problem: http://www.codeproject.com/Articles/882966/Fixing-Memory-Leaks-in-AngularJS-and-other-JavaScr
1 parent 8cdc924 commit 9ef0299

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

source/directives/uiTreeNode.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,12 +412,19 @@
412412
element.bind('touchend touchcancel mouseup',function(){$timeout.cancel(dragTimer);});
413413
};
414414
bindDrag();
415-
416-
angular.element($window.document.body).bind("keydown", function(e) {
417-
if (e.keyCode == 27) {
418-
scope.$$apply = false;
419-
dragEnd(e);
420-
}
415+
416+
var keydownHandler = function(e) {
417+
if (e.keyCode == 27) {
418+
scope.$$apply = false;
419+
dragEnd(e);
420+
}
421+
};
422+
423+
angular.element($window.document.body).bind("keydown", keydownHandler);
424+
425+
//unbind handler that retains scope
426+
scope.$on('$destroy', function () {
427+
angular.element($window.document.body).unbind("keydown", keydownHandler);
421428
});
422429
}
423430
};

0 commit comments

Comments
 (0)