November 2019
Intermediate to advanced
404 pages
12h 9m
English
The foreach loop keyword is a bit of a controversial issue in Unity development circles. It turns out that a lot of foreach loops implemented in Unity C# code will incur unnecessary heap memory allocations during these calls, as they allocate an Enumerator object as a class on the heap, instead of a struct on the stack. It all depends on the given collection's implementation of the GetEnumerator() method.
Since Unity 2018.1, Unity uses an upgraded Mono runtime (4.0.30319) and some compiler fixes many of the previous issues with foreach. As a consequence, foreach is no more a big issue in ...
Read now
Unlock full access