All delegates in framework should be weak instead of assign
| Originator: | an00na | ||
| Number: | rdar://16743058 | Date Originated: | 28-Apr-2014 |
| Status: | Open | Resolved: | |
| Product: | iOS SDK | Product Version: | 7.1.1 |
| Classification: | Serious Bug | Reproducible: | Always |
Summary: First of all assign delegates break Cocoa design patterns. Besides, things like NSFetchedResultsController sometimes outlive their owners. It would cause crashes. For example, I create an NSFetchedResultsController in my view controller and let view controller retain it as a property. So my view controller is the owner of this NSFetchedResultsController. I also set my view controller as the NSFetchedResultsController's delegate. Following Cocoa design patterns and using ARC, I shouldn't need to do anything in my view controller's dealloc method. However, sometimes, the NSFetchedResultsController is still alive for some period after the owner view controller is deallocated(I'm not sure why, maybe Core Data stack retains it somewhere) and continues to send delegate method calls to the deallocated view controller. The obvious workaround is to clear NSFetchedResultsController's delegate in its owner's dealloc method, which is unnecessary according to Cocoa design patterns.
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!