是否NG-包括有内存泄漏? [英] Does ng-include have memory-leak?
问题描述
我用 NG-包括
来切换不同的数据页,这将做大量的数据绘制的。
I use ng-include
to switch different data pages which will do a lot of data rendering.
我发现浏览器的内存使用量不断增加,永不后退。
I found the memory usage of the browser keeps growing, and never fall back.
在code是相当简单的。
The code is quite simple.
HTML code:
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>
它会显示一个无数据按钮,10个数据按钮加载不同的页面。
It will show a "no data" button, and 10 data buttons to load different pages.
角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;
})
});
与dataN.html网页:
And the "dataN.html" pages:
<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>
在nodata.html页:
The "nodata.html" page:
<div>No data yet.</div>
与data.json
And the "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"
}
这是一个现场演示:
<一个href=\"http://plnkr.co/edit/KGZVXIBws1kthgN2bxEJ?p=$p$pview\">http://plnkr.co/edit/KGZVXIBws1kthgN2bxEJ?p=$p$pview
当我打开现场演示,镀铬,初始化内存占用小于100M。然后我点击加载数据按钮,它会很快成长为300M,从来没有回落,即使我点击否数据按钮,载入nodata.html。
When I open the live demo with chrome, the initialize memory usage is less than 100M. Then I click the "Load data" buttons, it will soon grow to 300M and never fall back, even if I click "No data" button to load the "nodata.html".
这是正常的?请问 NG-包括
有内存泄漏还是我缺少什么?或内存使用情况还是蛮好的,我并不需要担心吗?
Is it normal? Does the ng-include
have memory leak or do I missing anything? Or the memory usage is just fine that I don't need to worry about it?
我创建了一个截屏来显示它:
I created a screencast to show it:
推荐答案
尝试升级到1.0.5版本。它不会出现这个问题。
我相信这是因为在1.0.3 / 4时,有模板顶级空白节点的内存泄漏。
Try upgrading to version 1.0.5. It doesn't appear to have this problem. I believe it is because there was a memory leak in 1.0.3/4 when there were top level white-space nodes in templates.
这篇关于是否NG-包括有内存泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!