@@ -101,6 +101,29 @@ function $RootScopeProvider() {
101101 $event . currentScope . $$destroyed = true ;
102102 }
103103
104+ function cleanUpScope ( $scope ) {
105+
106+ if ( msie === 9 ) {
107+ // There is a memory leak in IE9 if all child scopes are not disconnected
108+ // completely when a scope is destroyed. So this code will recurse up through
109+ // all this scopes children
110+ //
111+ // See issue https://github.com/angular/angular.js/issues/10706
112+ $scope . $$childHead && cleanUpScope ( $scope . $$childHead ) ;
113+ $scope . $$nextSibling && cleanUpScope ( $scope . $$nextSibling ) ;
114+ }
115+
116+ // The code below works around IE9 and V8's memory leaks
117+ //
118+ // See:
119+ // - https://code.google.com/p/v8/issues/detail?id=2073#c26
120+ // - https://github.com/angular/angular.js/issues/6794#issuecomment-38648909
121+ // - https://github.com/angular/angular.js/issues/1313#issuecomment-10378451
122+
123+ $scope . $parent = $scope . $$nextSibling = $scope . $$prevSibling = $scope . $$childHead =
124+ $scope . $$childTail = $scope . $root = $scope . $$watchers = null ;
125+ }
126+
104127 /**
105128 * @ngdoc type
106129 * @name $rootScope.Scope
@@ -897,16 +920,9 @@ function $RootScopeProvider() {
897920 this . $on = this . $watch = this . $watchGroup = function ( ) { return noop ; } ;
898921 this . $$listeners = { } ;
899922
900- // All of the code below is bogus code that works around V8's memory leak via optimized code
901- // and inline caches.
902- //
903- // see:
904- // - https://code.google.com/p/v8/issues/detail?id=2073#c26
905- // - https://github.com/angular/angular.js/issues/6794#issuecomment-38648909
906- // - https://github.com/angular/angular.js/issues/1313#issuecomment-10378451
907-
908- this . $parent = this . $$nextSibling = this . $$prevSibling = this . $$childHead =
909- this . $$childTail = this . $root = this . $$watchers = null ;
923+ // Disconnect the next sibling to prevent `cleanUpScope` destroying those too
924+ this . $$nextSibling = null ;
925+ cleanUpScope ( this ) ;
910926 } ,
911927
912928 /**
0 commit comments