diff options
| author | Pete Bacon Darwin | 2013-02-18 12:05:16 +0000 | 
|---|---|---|
| committer | Pete Bacon Darwin | 2013-02-18 13:04:24 +0000 | 
| commit | 1f23cfe9c751f84d9fc996df6d54961b2e46e868 (patch) | |
| tree | 5561063efeeded3a90014dcc870df5d06d441087 /src/ng/compile.js | |
| parent | 0fa8e47fb5d2df5aab820691696f19662669eed0 (diff) | |
| download | angular.js-1f23cfe9c751f84d9fc996df6d54961b2e46e868.tar.bz2 | |
fix(compile): should not leak memory when there are top level empty text nodes
The change to prevent <span> elements being wrapped around empty text nodes caused these empty text nodes to have scopes and controllers attached, through jqLite.data() calls, which led to memory leaks and errors in IE8.
Now we exclude all but document nodes and elements from having jqLite.data() set both in the compiler and in ng-view.
Fixes: #1968 and #1876
Diffstat (limited to 'src/ng/compile.js')
| -rw-r--r-- | src/ng/compile.js | 9 | 
1 files changed, 8 insertions, 1 deletions
| diff --git a/src/ng/compile.js b/src/ng/compile.js index 18adc2c9..2ed34f73 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -330,7 +330,14 @@ function $CompileProvider($provide) {          var $linkNode = cloneConnectFn            ? JQLitePrototype.clone.call($compileNodes) // IMPORTANT!!!            : $compileNodes; -        $linkNode.data('$scope', scope); + +        // Attach scope only to non-text nodes. +        for(var i = 0, ii = $linkNode.length; i<ii; i++) { +          var node = $linkNode[i]; +          if (node.nodeType == 1 /* element */ || node.nodeType == 9 /* document */) { +            $linkNode.eq(i).data('$scope', scope); +          } +        }          safeAddClass($linkNode, 'ng-scope');          if (cloneConnectFn) cloneConnectFn($linkNode, scope);          if (compositeLinkFn) compositeLinkFn(scope, $linkNode, $linkNode); | 
