Dev Tools to help find stray deallocs
| Originator: | cmkilger | ||
| Number: | rdar://11366461 | Date Originated: | 5/2/2012 |
| Status: | Closed | Resolved: | Duplicate |
| Product: | Developer Tools | Product Version: | 4.3.2 |
| Classification: | Enhancement | Reproducible: | Always |
Summary: In a -dealloc method, it is common for a developer who's been awake to long to inadvertently dealloc one of their instance variables rather than release it as they should. The developer tools can help prevent this from happening and diagnose the issues that occur when it does. Steps to Reproduce: 1. Wake up early and begin coding in your application. 2. Try to get as much work done as you can in the day. 3. Late in the day, when you're least (most?) expecting it, type "dealloc" instead of "release". (Especially if the ivar was an empty NSArray.) 4. Watch the application crash in strange and mysterious ways. 5. Run the application in Instruments with Zombies enabled. 6. Observe the weird jump in the retain count from some high number down to -1. 7. Go to bed. 8. The next day realize that somebody is probably calling -dealloc on this object somewhere. 9. Scour your code, attempting to use regular expressions, which you apparently haven't mastered as well as you had hoped. 10. Find the cause of the issue that you spent hours banging your head against your desk trying to figure out. 11. Give yourself one last face palm. 12. File an enhancement request at bugreport.apple.com, which will probably be resolved as a duplicate. Expected Results: 1) Assuming the clang static analyzer had been run, a result should have informed that dealloc was being called to something other than super. 2) In the backtrace in Instruments, a row marked as "Dealloc" could been the penultimate row, showing a backtrace of the call to dealloc. Actual Results: See Steps to Reproduce.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!