I have a simple coreata app that allows you to add items to a list, display in table view. When the user types in a new item, the following method is called:
- (zero) addNewItem: (NSString *) item {// Create a new instance of proprietary organization managed by Result Controls NSManagedObjectContext * context = [self.fetchedResultsController managedObjectContext]; NSEntityDescription * unit = [[self.fetchedResultsController fetchRequest] unit]; Item * newItem = [NSEntityDescription insertNewObjectForEntityForName: Managed object contex in [entity name]: context]; [New last setname: item]; // Save context NSError * Error = zero; If (! [Avoid context: & amp; error]) {// Error handle code NSLog (@ "Unsolved error% @,% @", error, [error user information]); Abortion (); } [Reference]; [Unit release]; [New iTam release]; The app always allows you to add an item to the list, but then you crash if you try to add a second if I "[new itam release];" If I remove, the app will allow you to add 4 list items, and then suddenly it will crash when you try to enter the fifth.
The app will only work properly if any of those release statements are removed at the end of the all three method, can anyone explain?
Objects are all autorelle (because you can always alloc init anything) So you do not have to release them yourself, it can not be guessed when your app may crash, but it will eventually crash.
Comments
Post a Comment