Why is foreach not recommended in unity

Source: Internet
Author: User
First look at the article https://www.zhihu.com/question/30334270 there is a picture

This explains the process of having a boxing after each foreach loop, and what is boxing? (See here: http://www.cnblogs.com/xiaoshi/archive/2008/05/28/1208902.html) The simple thing is to convert a value type to a reference type. The second line here is the boxing process. The third line is the unboxing process, which means that each time you use foreach, you apply a reference memory (40Bytes, a reference to a list) to the heap at the end, and the reference memory is recycled at gccollect time. The recycling process will be jammed. So unity does not use foreach because it generates garbage memory that causes the lag

Why is foreach not recommended in unity

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.