Reputation: 15
I wonder if there's a way to create let's say 1 MB object other than a very big list. It could be anything as long as it's reference type. I want to use it in memory profiler tests so I don't need any special behavior. Maybe some unit test engine or Moq have such feature?
Upvotes: 0
Views: 472
Reputation: 3243
An array is pretty straightforward to create.
Console.WriteLine($"Allocated memory: {GC.GetTotalMemory(false)}");
var array = new byte[1024 * 1024];
Console.WriteLine($"Allocated memory: {GC.GetTotalMemory(false)}");
Output:
Allocated memory: 160872
Allocated memory: 1209504
Upvotes: 2