NSManagedObjectContext crash if autoreleased while deallocating
| Originator: | me | ||
| Number: | rdar://10713687 | Date Originated: | 18-Jan-2012 01:23 AM |
| Status: | Open | Resolved: | |
| Product: | Mac OS X | Product Version: | 10.7.3 (11D42) |
| Classification: | Crash/Hang/Data Loss | Reproducible: | Always |
In the attached code, a NSManagedObject subclass overrides -willTurnIntoFault and does a retain-autorelease on its managed object context. (Both ARC and non-ARC code are included; both trigger the same issue.) When the managed object context is released (with objects of this class registered), it enters the autorelease pool as a zombie, and is quickly sent -release, which crashes. Things that make this a bigger deal: 1. With ARC, it's hard to control retain/autorelease behavior. 2. With nested contexts, short-lived contexts will be more common. In this case, calling -refreshObject:mergeChanges: on every registered object (#if'd out in the attached code) appears to force correct ordering. This general pattern -- a master object is deallocating; children do a retain-autorelease, then master object gets a zombie release -- has come up other times too. (Notably when I had a rule editor's rows bound to a view controller; the binding was established in -awakeFromNib, but calling -unbind: in the view controller's -dealloc led to this same situation.)
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!
main-arc.m