Skip to content

Commit

Permalink
Fix memory leak by canceling timers in $destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
widmoser committed Jul 29, 2016
1 parent c3913d6 commit 29f653f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions dist/tileview.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@
angular.element($window).on('resize', onResize);
scope.$on('$destroy', function () {
angular.element($window).off('resize', onResize);
// unregister all timers:
if (resizeTimeout !== undefined) {
$timeout.cancel(resizeTimeout);
}
if (scrollEndTimeout !== undefined) {
$timeout.cancel(scrollEndTimeout);
}
if (debounceTimeout !== undefined) {
$timeout.cancel(debounceTimeout);
}
removeAll();
});
function removeElement(el) {
Expand Down
12 changes: 12 additions & 0 deletions src/tileview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ declare const angular: any;

scope.$on('$destroy', function () {
angular.element($window).off('resize', onResize);

// unregister all timers:
if (resizeTimeout !== undefined) {
$timeout.cancel(resizeTimeout);
}
if (scrollEndTimeout !== undefined) {
$timeout.cancel(scrollEndTimeout);
}
if (debounceTimeout !== undefined) {
$timeout.cancel(debounceTimeout);
}

removeAll();
});

Expand Down

0 comments on commit 29f653f

Please sign in to comment.