4

I have an NSOutlineView which should dealloc when removed from screen but since that is not happening I suspect another object is holding a reference to it.

Is it possible to see how many references and which objects that have a reference to an object/view in Xcode or the Profiler?

Edit: Although I did find another solution I still would like to know if there is anyway to see a list of objects holding (retaining) a certain object/view

d00dle
  • 1,276
  • 1
  • 20
  • 33

1 Answers1

15

You're never going to be able to get a list of 'objects retaining a certain object' because the refcount is merely a count - there is no FIFO or LIFO or any sort of direct matching between a retain and a release - it's just a count.

What you can do is use Instruments to display a list of all objects responsible for retain call and release call on your object. Use the Allocations tool, make sure "Record Reference Counts" is checked. Then you can use the Statistics view to see all living objects in your running app. Click the little right-arrow to the right of any object to see a table of retain/release calls for that object. This is where you can see the refcount going up and down and hopefully find the object that is 'mysteriously' retaining and/or not releasing.

Some common over-retention problems are: a. delegates needs to be weak properties, b. need to unregister any observers in the view controller or window controller, c. a view is retained when inserted into a view hierarchy.

Rupert Pupkin
  • 742
  • 6
  • 9
  • Great explanation. Also your quick guide for the Allocation tool actually got me to understand its use better. – d00dle Apr 18 '15 at 18:52