角JS NG-重复消耗更多的浏览器内存 [英] Angular JS ng-repeat consumes more browser memory
问题描述
我有以下的code
<table>
<thead><td>Id</td><td>Name</td><td>Ratings</td></thead>
<tbody>
<tr ng-repeat="user in users">
<td>{{user.id}}</td>
<td>{{user.name}}</td>
<td><div ng-repeat="item in items">{{item.rating}}</div></td>
</tr>
</tbody>
</table>
用户来说,只有编号和名称用户对象的数组。用户数量的对象数组 - 150
users is an array of user objects with only id and name. number of user objects in array - 150
物品是唯一的ID和评价项目对象的数组。项目的数量对象数组 - 150
items is an array of item objects with only id and rating. number of item objects in array - 150
当我使这个浏览器,它需要大约堆内存250MB的,当我试图在我的铬分析 - v23.0.1271.95
When i render this in browser, it takes about 250MB of heap memory when i tried profiling in my chrome - v23.0.1271.95.
我使用AngularJS V1.0.3。
I am using AngularJS v1.0.3.
有没有用的问题的角度还是我在这里做什么错事?
Is there an issue with angular or am i doing anything wrong here?
下面是JS提琴
http://jsfiddle.net/JSWorld/WqSGR/5/
推荐答案
那么它不是NG-重复本身。我认为这是你与添加绑定的事实{{item.rating}}
Well it's not the ng-repeat per se. I think it's the fact that you are adding bindings with the {{item.rating}}.
所有这些绑定注册的范围,使手表:
All those bindings register watches on the scope so:
- 150 * 2 = 300(为2用户的相关信息)
- 150 * 150 = 22500(对评级信息)
- 的22800手表功能共有+ 22800的DOM元素。
这将推动内存为250MB的想像值
That would push the memory to a conceivable value of 250MB
From Databinding in angularjs
您真的不能表现出比更多的 2000 的信息片段到
人类在单页上。什么比这更是非常糟糕的用户界面,以及
人类无法处理此反正。
You can't really show more than about 2000 pieces of information to a human on a single page. Anything more than that is really bad UI, and humans can't process this anyway.
这篇关于角JS NG-重复消耗更多的浏览器内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!