环境
- Unity 4.6.4 / Windows
测试代码
![](https://img.haomeiwen.com/i1835687/34bd8121ec22dbc6.png)
测试成绩
![](https://img.haomeiwen.com/i1835687/f70a39f1c2b55739.png)
结论
foreach存在bug,会导致GC Alloc,并且效率低下;
使用GetEnumerator代替,没有GC,并且速度快10倍!
建议迭代操作中,List使用for,Dictionary使用GetEnumerator
foreach存在bug,会导致GC Alloc,并且效率低下;
使用GetEnumerator代替,没有GC,并且速度快10倍!
建议迭代操作中,List使用for,Dictionary使用GetEnumerator
本文标题:Unity Mono的foreach造成GC Alloc的BUG
本文链接:https://www.haomeiwen.com/subject/juuwrttx.html
网友评论