问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/12113652/how-do-you-find-out-what-is-retaining-an-object-in-instruments