-3

What is the memory footprint of following code something like number of objects on heap.

for (int i = 0; i < 10000; i++)
        {
            await MyMethod();
        }
TRS
  • 1,947
  • 4
  • 26
  • 49
  • 4
    You can check that yourself in Visual Studio. Take a look [here](https://stackoverflow.com/questions/9404946/how-to-measure-memory-usage-with-c-sharp-as-we-can-do-in-java/9404984). – Adrian Feb 28 '19 at 10:58

1 Answers1

1

This question is probably a duplicate.

But the following calls to the VirtualMemorySize64 method will get you the current size of the memory in bytes. If you wrap the operation you want to monitor and grab a snapshot before and after you can work out the total increase here.

Docs link here.

using System.Diagnostics;

...

long start = Process.GetCurrentProcess().VirtualMemorySize64;

for (int i = 0; i < 10000; i++)
{
    await MyMethod();
}

long end = Process.GetCurrentProcess().VirtualMemorySize64;

// You can then get the total difference in bytes
long diff = end - start;
Dan Gardner
  • 1,069
  • 2
  • 13
  • 29