Autorelease pool in main() in Xcode templates is wrong
| Originator: | kusterer | ||
| Number: | rdar://9724315 | Date Originated: | 05-Jul-2011 09:38 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | 4 |
| Classification: | Serious Bug | Reproducible: | Not Applicable |
The Xcode templates for new iPhone applications create an NSAutoreleasePool in their main() function. This is wrong, as any object released without a pool will end up in this autorelease pool, which persists for the entire duration of the application. So effectively the object is still leaked. Usually, if there is no autorelease pool in place, the runtime logs an error message about the missing pool and tells the developer to set a breakpoint on _NSAutoreleaseNoPool to find where the pool-less autorelease happens. The top-level NSAutoreleasePool as found in the templates thus actually *hides* this leak from the users. UIApplicationMain() should build its own autorelease pool as needed. If someone thinks they really need to run ObjC code before calling UIApplicationMain() (and they can't do the same work in applicationDidFinishLaunching: or the likes), they can always create a pool *before* UIApplicationMain(). Since UIApplicationMain() is documented to never return (like exit()), there is no point in having commands following it anyway. The pool would never get released. Please fix the templates, or provide an FAQ or other documentation why this should be necessary on iOS (when it's clearly unneeded on Mac).
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!