我如何查看哪些引用阻止我的 ref 对象在 c++/cx 中被删除?

How can I see what references are keeping my ref objects from being deleted in c++/cx?

我在我的 UWP 项目的一个地方使用了 myclass^,但我怀疑它们在超出范围时实际上并没有被删除。所以我创建了一个为 myclass^ 调用 __debugbreak() 的析构函数,以确保它被调用。我的项目本来应该接到 40 个电话,但我接到了一个。据我了解,带有帽子 (^) 的类型基本上是 shared_ptrs,所以如果我的对象没有被删除,可能是因为项目中的其他内容持有对它的引用。我如何对此进行诊断并查看 Visual Studio 中对该对象的其他引用?

How can I diagnose this and see what other references to the object there are in Visual Studio?

您可以使用 Visual Studio 中的内存使用工具诊断此问题。详细步骤可以参考Diagnosing memory issues with the new Memory Usage Tool in Visual Studio。您可以拍摄快照以捕获应用程序内存的状态。

当您 select 一个类型或一个实例时,您可以看到它的引用,这是您将用来理解为什么某些类型或实例在垃圾收集期间没有被收集的主要视图 运行。