From 73745154a7a486b84b916907b298eb2d5c360c5d Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Fri, 1 May 2015 14:47:29 +0100 Subject: [PATCH] fix($rootScope): stop memory leak in IE9 DO NOT MERGE This is a work in progress for discussion - it is not ideal is lacking tests. Closes #10706 --- src/ng/rootScope.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/ng/rootScope.js b/src/ng/rootScope.js index c2310a1f11a3..8e7f05bd7384 100644 --- a/src/ng/rootScope.js +++ b/src/ng/rootScope.js @@ -101,6 +101,15 @@ function $RootScopeProvider() { $event.currentScope.$$destroyed = true; } + function cleanUpScope($scope) { + // Recurse bottom up + $scope.$$childHead && cleanUpScope($scope.$$childHead); + $scope.$$nextSibling && cleanUpScope($scope.$$nextSibling); + + $scope.$$nextSibling = $scope.$$prevSibling = $scope.$$childHead = + $scope.$$childTail = $scope.$root = $scope.$$watchers = null; + } + /** * @ngdoc type * @name $rootScope.Scope @@ -900,6 +909,13 @@ function $RootScopeProvider() { this.$on = this.$watch = this.$watchGroup = function() { return noop; }; this.$$listeners = {}; + var that = this; + if (msie === 9) { + this.$evalAsync(function() { + cleanUpScope(that); + }); + } + // All of the code below is bogus code that works around V8's memory leak via optimized code // and inline caches. //