diff --git a/src/features/edit/js/gridEdit.js b/src/features/edit/js/gridEdit.js index deb1cf3b81..affdd55b14 100644 --- a/src/features/edit/js/gridEdit.js +++ b/src/features/edit/js/gridEdit.js @@ -507,7 +507,11 @@ }); - $scope.$on( '$destroy', rowWatchDereg ); + $scope.$on('$destroy', function destroyEvents() { + rowWatchDereg(); + // unbind all jquery events in order to avoid memory leaks + $elm.off(); + }); function registerBeginEditEvents() { $elm.on('dblclick', beginEdit); @@ -1042,6 +1046,11 @@ return true; }); + + $scope.$on('$destroy', function unbindEvents() { + // unbind all jquery events in order to avoid memory leaks + $elm.off(); + }); } }; } @@ -1185,6 +1194,11 @@ } return true; }); + + $scope.$on('$destroy', function unbindEvents() { + // unbind jquery events to prevent memory leaks + $elm.off(); + }); } }; } @@ -1277,7 +1291,7 @@ } }; - $elm[0].addEventListener('change', handleFileSelect, false); // TODO: why the false on the end? Google + $elm[0].addEventListener('change', handleFileSelect, false); $scope.$on(uiGridEditConstants.events.BEGIN_CELL_EDIT, function () { $elm[0].focus(); @@ -1287,11 +1301,15 @@ $scope.$emit(uiGridEditConstants.events.END_CELL_EDIT); }); }); + + $scope.$on('$destroy', function unbindEvents() { + // unbind jquery events to prevent memory leaks + $elm.off(); + $elm[0].removeEventListener('change', handleFileSelect, false); + }); } }; } }; }]); - - })(); diff --git a/src/features/move-columns/js/column-movable.js b/src/features/move-columns/js/column-movable.js index eaf5432fdc..10aafcca5e 100644 --- a/src/features/move-columns/js/column-movable.js +++ b/src/features/move-columns/js/column-movable.js @@ -565,6 +565,8 @@ movingElm.css({'width': reducedWidth + 'px'}); } }; + + $scope.$on('$destroy', offAllEvents); } } }; diff --git a/src/features/selection/js/selection.js b/src/features/selection/js/selection.js index 9cebe60cb9..5733f87742 100644 --- a/src/features/selection/js/selection.js +++ b/src/features/selection/js/selection.js @@ -736,6 +736,10 @@ window.setTimeout(function () { evt.target.onselectstart = null; }, 0); } } + + $scope.$on('$destroy', function unbindEvents() { + $elm.off(); + }); } }; }]); diff --git a/src/js/core/directives/ui-grid-menu.js b/src/js/core/directives/ui-grid-menu.js index 53b24c3d49..3b9be16d65 100644 --- a/src/js/core/directives/ui-grid-menu.js +++ b/src/js/core/directives/ui-grid-menu.js @@ -196,13 +196,11 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, i18 angular.element($window).on('resize', applyHideMenu); } - $scope.$on('$destroy', function () { - angular.element(document).off('click touchstart', applyHideMenu); - }); - - - $scope.$on('$destroy', function() { + $scope.$on('$destroy', function unbindEvents() { angular.element($window).off('resize', applyHideMenu); + angular.element(document).off('click touchstart', applyHideMenu); + $elm.off('keyup', checkKeyUp); + $elm.off('keydown', checkKeyDown); }); if (uiGridCtrl) { diff --git a/src/js/core/directives/ui-grid-viewport.js b/src/js/core/directives/ui-grid-viewport.js index fe13780c1a..e76da574d4 100644 --- a/src/js/core/directives/ui-grid-viewport.js +++ b/src/js/core/directives/ui-grid-viewport.js @@ -133,7 +133,9 @@ } } - + $scope.$on('$destroy', function unbindEvents() { + $elm.off(); + }); }, controller: ['$scope', function ($scope) { this.rowStyle = function (index) { diff --git a/src/js/core/services/ui-grid-util.js b/src/js/core/services/ui-grid-util.js index 270cb30b25..06ea15c24b 100644 --- a/src/js/core/services/ui-grid-util.js +++ b/src/js/core/services/ui-grid-util.js @@ -1278,6 +1278,11 @@ module.service('gridUtil', ['$log', '$window', '$document', '$http', '$templateC for ( var i = mouseWheeltoBind.length; i; ) { $elm.on(mouseWheeltoBind[--i], cbs[fn]); } + $elm.on('$destroy', function unbindEvents() { + for ( var i = mouseWheeltoBind.length; i; ) { + $elm.off(mouseWheeltoBind[--i], cbs[fn]); + } + }); }; s.off.mousewheel = function (elm, fn) { var $elm = angular.element(elm);