こんにちは。クライアント開発の taraba_ です。 今日は、Unity 上で .NET の System.Collections.Generic 名前空間にある IEnumerable<T> 実装コレクション(と配列)を foreach にかけた際に、GC Alloc が発生する条件を調べました。 調査環境は Unity 2018.4.14f1 です。 (2020.1.0a24 でも同様の結果でした) まずは以下の疑似コードとプロファイル結果をご覧ください。 // 直接持つ private int[] _array = new[] {1, 2, 3, 4}; private List<int> _list = new List<int>() {1, 2, 3, 4}; private Dictionary<int, int> _dictionary = new Dictionary<i
