美文网首页unity优化Unity的那些事Unity技术分享
Unity Mono的foreach造成GC Alloc的BUG

Unity Mono的foreach造成GC Alloc的BUG

作者: 陈凯利 | 来源:发表于2016-05-18 17:18 被阅读1369次

环境

  • Unity 4.6.4 / Windows

测试代码

测试代码

测试成绩

测试成绩

结论

foreach存在bug,会导致GC Alloc,并且效率低下;
使用GetEnumerator代替,没有GC,并且速度快10倍!

建议迭代操作中,List使用for,Dictionary使用GetEnumerator

相关文章

网友评论

本文标题:Unity Mono的foreach造成GC Alloc的BUG

本文链接:https://www.haomeiwen.com/subject/juuwrttx.html