2

In Visual Studio 2022, when I use the Memory Usage tool and set it to "Enable native heap profiling with snapshots", it only includes managed allocations, not native allocations.

In Visual Studio 2019, when I run the same tool on the same project, it does include native allocations.

The debug profile has "Enable native code debugging" turned on. (Though this doesn't seem necessary for VS 2019 to capture a native heap.)

What is it about my VS 2022 installation or settings that are preventing native snapshots? Or am I missing something in the VS 2022 UI?

The test code:

class Program
{
    private static void Main(string[] args)
    {
        System.Console.WriteLine("Take first snapshot");
        System.Console.ReadKey();

        // Alloc 1 GB unmanaged memory
        var handles = new System.IntPtr[100];
        for (int i = 0; i < handles.Length; i++)
        {
            handles[i] = System.Runtime.InteropServices.Marshal.AllocHGlobal(10 * 1024 * 1024);
        }

        System.Console.WriteLine("Take second snapshot");
        System.Console.ReadKey();
    }
}

In VS 2019:

VS 2019 setting Memory Usage to Mixed

VS 2019 snapshot has Native Heap

In VS 2022:

VS 2022 setting Memory Usage to Enable Native heap profiling

VS 2022 snapshot has no Native Heap

owen_shiny
  • 21
  • 2
  • The Diagnostics Tools Window memory profiling does capture the native heap, so I am able to get the info I want. Though the Diagnostics Tools doesn't allow me to save the data.
    Also the Memory Usage Tool hangs taking the third or fourth snapshot, while I don't have that problem with the Diagnostics Tools Window.
    I wouldn't expect these two ways of calling the same tools to behave differently. Why can't they behave the same?
    – owen_shiny Oct 01 '22 at 01:00

0 Answers0