Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you find out what is retaining an object in Instruments?

I've recently converted my iOS project over to ARC. One of the view controllers is not calling its dealloc method and is not being dealloc'ed according to Instruments.

I've double checked all of my properties and set the appropriate ones to weak. I've also made sure that anything that has the view controller as a delegate has it unset on viewWillDisappear but the view still sticks around in memory.

I'm a newbie at Instruments: how can I tell what is retaining this view?

like image 930
James Avatar asked Aug 24 '12 16:08

James


People also ask

How to find retain cycle ios?

If you are using Xcode 8 or above, you can use the memory graph thingy to see what object holds a reference to what object. Now you can clearly see that it is retained by a closure! That is how you use the memory graph to see where you should put weak-references and avoid retain cycles.

How do I use instruments in Xcode?

You can access the instruments by using Product ➔ Profile from the Xcode menu for which the shortcut handle is ⌘ + I . This will rebuild your product and opens the Xcode Instruments overview.


1 Answers

Well if you are really stuck and the program is complex (or abstracted, in the case of ARC), you can bring out the cannons:

  • Open your Xcode project
  • Choose the executable (if needed)
  • Press cmd+i (Profile)
  • Choose the 'Leaks' Instrument in Le Wizard (if needed)
  • Press Return to begin profiling
  • Exercise your app
  • Press 'Stop' in Instruments
  • Verify the 'Allocations' instrument is selected
  • Click and Hold the Popup Button named 'Statistics'
  • Select the Objects List item
  • Locate the allocation you are interested in, among the records in the Objects List
  • Select that allocation/object
  • Click the 'detail arrow' to the right of the address in the table view cell of that allocation
  • Now you see all events related to the allocation (allocation, free, reference count operations)
  • Press cmd+shift+e for Extended Detail
  • Go through the events in this list, and locate the imbalance you seek.
like image 55
justin Avatar answered Oct 17 '22 02:10

justin