如何查看哪些引用阻止我的 ref 对象在 c++/cx 中被删除? [英] How can I see what references are keeping my ref objects from being deleted in c++/cx?

查看:22
本文介绍了如何查看哪些引用阻止我的 ref 对象在 c++/cx 中被删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

如何诊断并查看 Visual Studio 中对对象的其他引用?

您可以使用 Visual Studio 中的内存使用工具对此进行诊断.有关详细步骤,您可以参考

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

I use myclass^ in one place in my UWP project, but I suspected that they weren't actually being deleted when they went out of scope. So I made a destructor that called __debugbreak() for myclass^ to make sure that was getting called. Instead of the 40 calls I should be getting for my project, I got one. To my understanding, types with hats (^) are basically shared_ptrs so if my object isn't getting deleted, it's probably because something else in the project holds a reference to it. How can I diagnose this and see what other references to the object there are in Visual Studio?

解决方案

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

You could diagnose this with Memory Usage Tool in Visual Studio. For detail steps, you could refer Diagnosing memory issues with the new Memory Usage Tool in Visual Studio. And you could take snapshot in order to capture the state of the application memory.

When you select a type or an instance, you could see its references, this is the primary view that you will be using to understand why certain types or instances are not being collected during a garbage collection run.

这篇关于如何查看哪些引用阻止我的 ref 对象在 c++/cx 中被删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆