Reputation: 6679
So, at a breakpoint, I have a random object instance. I want to figure out which objects have a pointer to this object. Is there a way to see this in the debugger console? Maybe something that shows me all the objects that have a retain on the object?
Example: I have a NSViewController
instance and I want to see all the other objects that hold a pointer this view controller instance. This would be helpful because it would allow me to see the view controller hierarchy that is encapsulating my instance.
Just a crazy thought I had that would really help at times.
Upvotes: 15
Views: 5696
Reputation: 8012
In lldb, use command script import lldb.macosx.heap
to install some memory-searching functions. The ptr_refs command should be able to do what you want; use ptr_refs --help
to learn more.
Upvotes: 34
Reputation: 2267
Not an efficient solution, or applicable in all cases, but you could encapsulate the object you're looking for in an accessor method on one of your classes, and put a breakpoint inside. By stepping through the end of the accessor method, you can eventually see all the call points.
Alternatively, you can remove the definition of the variable, and the compiler will spit out a ton of errors, each will also be a call to this object.
I'd suggest using ARC if you're not already. Ideally your code wouldn't be messy enough that you wouldn't be able to identify references by reading through the code, ARC can help a little bit in that department
Upvotes: 0