无法在 Visual Studio 2022 内存使用工具中拍摄本机内存快照

问题描述 投票:0回答:1

在 Visual Studio 2022 中,当我使用内存使用工具并将其设置为“使用快照启用本机堆分析”时,它仅包括托管分配,而不包括本机分配。

在 Visual Studio 2019 中,当我在同一个项目上运行相同的工具时,它确实包含本机分配。

调试配置文件已打开“启用本机代码调试”。 (尽管这对于 VS 2019 来说似乎没有必要捕获本机堆。)

我的 VS 2022 安装或设置阻止本机快照的原因是什么?或者我在 VS 2022 UI 中遗漏了一些东西?

测试代码:

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();
    }
}

VS 2019:

VS 2019 setting Memory Usage to Mixed

VS 2019 snapshot has Native Heap

VS 2022:

VS 2022 setting Memory Usage to Enable Native heap profiling

VS 2022 snapshot has no Native Heap

c# profiling visual-studio-2022 diagnostic-tools heap-profiling
1个回答
0
投票

需要选中“启用本机调试”才能正常工作。 Screen shot of .Net project setting

Screen shot of diagnostic tools

© www.soinside.com 2019 - 2024. All rights reserved.