Calling becomeFirstResponder on a modal view causes extra release
| Originator: | jesse.crossen | ||
| Number: | rdar://9864248 | Date Originated: | 29-Jul-2011 01:35 PM |
| Status: | Open | Resolved: | |
| Product: | iPhone SDK | Product Version: | 4.3 |
| Classification: | Crash | Reproducible: | Always |
Summary: Calling becomeFirstResponder on a view controller presented modally from application:didFinishLaunchingWithOptions: causes NSAutoreleasePool to release the view controller without a corresponding autorelease call. Steps to Reproduce: 1. Create a subclass of UIViewController that returns YES for canBecomeFirstResponder. 2. In the view controller's implementation of viewDidAppear, call [self becomeFirstResponder]. 3. Create an instance of the view controller in application:didFinishLaunchingWithOptions: and present it modally. 4. Dismiss the view controller, show an action sheet, and tap a button on the action sheet. 5. The view controller is accessed from UIKit code, even though it has been deallocated, throwing EXC_BAD_ACCESS. Expected Results: No references to the modal view controller are retained in user code, so it should either be deallocated cleanly with no dead references or it should not be deallocated if there are still references to it. Actual Results: When run in the Allocations Instrument, the culprit seems to be a spurious release sent from NSAutoreleasePool which causes the view controller instance to deallocate prematurely. None of the user code has autoreleased the instance, and no autorelease call is recorded by the Allocations Instrument, meaning that the instance must have been added to the pool by UIKit. Regression: Unknown. Notes: Attached is an example app that replicates the bug. Run it, tap the blue screen to dismiss the modal view controller, tap Action on the main screen, and tap Delete. The app should crash. Also included in the provided zip archive are a screenshot of the Allocations Instrument and a crash log from an iPod touch.
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!