public static void MatchCollections() { MemoryProfiler memoryProfiler = MemoryProfiler.StartNew(); int itemCount = 10000000; MatchCollection2 matches1 = Factory.CreateMatchCollection(Enumerable.Range(1, itemCount) .Select(i => Factory.CreateMatch(i, i, "x"))); memoryProfiler.CollectGC(); Console.WriteLine("Matches: {0:#,##0}", matches1.Count); displayMemoryProfiler(memoryProfiler, itemCount); // 41 bytes/match (itemCount = 10,000,000) // 36.9 bytes/match (itemCount = 13,000,000) memoryProfiler.Reset(); Match2[] matches2 = Enumerable.Range(1, itemCount) .Select(i => Factory.CreateMatch(i, i, "x")) .ToArray(); memoryProfiler.CollectGC(); Console.WriteLine("Matches: {0:#,##0}", matches2.Length); displayMemoryProfiler(memoryProfiler, itemCount); // 36 bytes/match (itemCount = 10,000,000) // 36 bytes/match (itemCount = 13,000,000) memoryProfiler.Reset(); List <Match2> matches3 = Enumerable.Range(1, itemCount) .Select(i => Factory.CreateMatch(i, i, "x")) .ToList(); memoryProfiler.CollectGC(); Console.WriteLine("Matches: {0:#,##0}", matches3.Count); displayMemoryProfiler(memoryProfiler, itemCount); // 38.7 bytes/match (itemCount = 10,000,000) // 37.2 bytes/match (itemCount = 13,000,000) memoryProfiler.Reset(); List <int> ints1 = Enumerable.Range(1, itemCount) .ToList(); memoryProfiler.CollectGC(); Console.WriteLine("Ints: {0:#,##0}", ints1.Count); displayMemoryProfiler(memoryProfiler, itemCount); // 6.7 bytes/match (itemCount = 10,000,000) // 5.2 bytes/match (itemCount = 13,000,000) memoryProfiler.Reset(); int[] ints2 = Enumerable.Range(1, itemCount) .ToArray(); memoryProfiler.CollectGC(); Console.WriteLine("Ints: {0:#,##0}", ints2.Length); displayMemoryProfiler(memoryProfiler, itemCount); // 4 bytes/match (itemCount = 10,000,000) // 4 bytes/match (itemCount = 13,000,000) }