Does ng-include have a memory leak?

I use ng-include to switch various data pages that will do a lot of data.

I found that the memory usage in the browser continues to grow and never returns.

code

The code is pretty simple.

HTML code:

 <body ng-controller="MainCtrl"> <div> <button ng-click="url='nodata.html'">No data</button> <button ng-repeat="i in getNumArray(10)" ng-click="loadData(i)">Load data {{i}}</button> </div> <hr/> [{{url}}] <div ng-include="url"></div> </body> 

It will show a β€œno data” button and 10 data buttons to load different pages.

Angular Code:

 app.controller('MainCtrl', function($scope) { $scope.url = "nodata.html"; $scope.loadData = function(n) { $scope.url = "data" + n + ".html"; } $scope.getNumArray = function(n) { var arr = []; for(var i =0;i<n;i++) { arr.push(i); } return arr; } }); app.controller('DataCtrl', function($scope, $http){ $http.get('data.json').success(function(data){ $scope.data = data; }) }); 

And the "dataN.html" page:

 <div ng-controller="DataCtrl"> <table ng-repeat="x in getNumArray(500)"> <tbody> <tr> <td>{{data["key0"]}}</td> <td>{{data["key1"]}}</td> <td>{{data["key2"]}}</td> <td>{{data["key3"]}}</td> <td>{{data["key4"]}}</td> <td>{{data["key5"]}}</td> <td>{{data["key6"]}}</td> <td>{{data["key7"]}}</td> <td>{{data["key8"]}}</td> <td>{{data["key9"]}}</td> </tr> </tbody> </table> </div> 

Page "nodata.html":

 <div>No data yet.</div> 

And "data.json":

 { "key0": "sdf sdf sdf sdf sdf sdf sdf sdf sdf sd fds fds fsd fds fds fds fds fsd fds fds f", "key1": "sdf sdf sdf sdf sdf sdf sdf sdf sdf sd fds fds fsd fds fds fds fds fsd fds fds f", "key2": "sdf sdf sdf sdf sdf sdf sdf sdf sdf sd fds fds fsd fds fds fds fds fsd fds fds f", "key3": "sdf sdf sdf sdf sdf sdf sdf sdf sdf sd fds fds fsd fds fds fds fds fsd fds fds f", "key4": "sdf sdf sdf sdf sdf sdf sdf sdf sdf sd fds fds fsd fds fds fds fds fsd fds fds f", "key5": "sdf sdf sdf sdf sdf sdf sdf sdf sdf sd fds fds fsd fds fds fds fds fsd fds fds f", "key6": "sdf sdf sdf sdf sdf sdf sdf sdf sdf sd fds fds fsd fds fds fds fds fsd fds fds f", "key7": "sdf sdf sdf sdf sdf sdf sdf sdf sdf sd fds fds fsd fds fds fds fds fsd fds fds f", "key8": "sdf sdf sdf sdf sdf sdf sdf sdf sdf sd fds fds fsd fds fds fds fds fsd fds fds f", "key9": "sdf sdf sdf sdf sdf sdf sdf sdf sdf sd fds fds fsd fds fds fds fds fsd fds fds f" } 

Here is a live demo:

http://plnkr.co/edit/KGZVXIBws1kthgN2bxEJ?p=preview

When I open the demo with chrome, the initialization memory usage is less than 100 MB. Then I click the "Download Data" buttons, it will soon grow to 300 M and never back down, even if I click the "No Data" button to download "nodata.html".

This is normal? Does ng-include a memory leak or am I not seeing anything? Or is memory usage just fine that I don't need to worry about that?

screencast

I created a screencast to show it:

ng-include

+6
source share
2 answers

Try upgrading to version 1.0.5. This problem does not seem to have it. I believe that this is due to the fact that a memory leak occurred in 1.0.3 / 4 when there were top-level top-level nodes in the templates.

+2
source

Stackoverflow is not a place to download errors. Please write to the question https://github.com/angular/angular.js/issues and continue the discussion there.

I simplified use in one file: http://plnkr.co/edit/Wm4YRsLGJUDqUcww2DQZ?p=preview

Here is what I learned.

  • Only leak on Windows does not leak on Mac OS X
  • Only merges into the plunker. When I run it outside the plunker, it works great.

Can you reproduce the problem outside the plunker?

+2
source

All Articles