Archived Friendly Reminder: foreach keyword in C# allocates memory in Unity (gamasutra.com)
submitted ago by Zesty
Posted by: Zesty
Posting time: 4.5 years ago on
Last edit time: never edited.
Archived on: 2/12/2017 1:51:00 AM
Views: 349
SCP: 10
11 upvotes, 1 downvotes (92% upvoted it)
Archived Friendly Reminder: foreach keyword in C# allocates memory in Unity (gamasutra.com)
submitted ago by Zesty
view the rest of the comments →
[–] rumayor ago
Did you read the article? It does not have to do anything with C#, it is a compiler bug on Mono. Also some of his recommendations make sense on code that is executed on a tight loop, but is fine to do on instances where it is not executed all the time.
[–] [deleted] ago
[–] rumayor ago
It is not such a difference if you start to write multi threaded programs; if you want high performance in C# you need to be careful how you program; so you don't overload the garbage collector. The run time converts it to a low level representation that is not far away form bare metal languages; I think the trade off is good in most cases; but I would agree with you that for games it is not the best match as the garbage collection interrupts the program execution, but for numeric analysis or other applications it is a very good match.