问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/48106743/how-can-i-see-what-references-are-keeping-my-ref-objects-from-being-deleted-in-c