From 920a3804136d49cdaf7bc2712f5832bc50409dc9 Mon Sep 17 00:00:00 2001 From: Andy Gurden Date: Tue, 13 Aug 2013 12:55:06 +0100 Subject: fix($timeout): clean deferreds immediately after callback exec/cancel Make sure $timeout callbacks are forgotten about immediately after execution or cancellation. Previously when passing invokeApply=false, the cleanup used $q and so would be pending until the next $digest was triggered. This does not make a large functional difference, but can be very visible when looking at memory consumption of an app or debugging around the $$asyncQueue - these callbacks can have a big retaining tree. --- src/ng/timeout.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/ng/timeout.js b/src/ng/timeout.js index 81d09e89..6cb62d7a 100644 --- a/src/ng/timeout.js +++ b/src/ng/timeout.js @@ -45,17 +45,15 @@ function $TimeoutProvider() { deferred.reject(e); $exceptionHandler(e); } + finally { + delete deferreds[promise.$$timeoutId]; + } if (!skipApply) $rootScope.$apply(); }, delay); - cleanup = function() { - delete deferreds[promise.$$timeoutId]; - }; - promise.$$timeoutId = timeoutId; deferreds[timeoutId] = deferred; - promise.then(cleanup, cleanup); return promise; } @@ -77,6 +75,7 @@ function $TimeoutProvider() { timeout.cancel = function(promise) { if (promise && promise.$$timeoutId in deferreds) { deferreds[promise.$$timeoutId].reject('canceled'); + delete deferreds[promise.$$timeoutId]; return $browser.defer.cancel(promise.$$timeoutId); } return false; -- cgit v1.2.3