开发者

Deallocated view controller causing EXC_BAD_ACCESS because of fetched results controller update

I have a navigation app with 3 view controllers on the stack. The navigation root pushes Availab开发者_JS百科leItemsViewController, passing a managed object context to it.

This view, which is a table view that uses a fetched results controller to populate it, has an add button which pushes another controller (CreateNewItemViewController) I pass that context off to it.

In CreateNewItemViewController I create a managed object, save it to the context, then pop the view controller.

I can go back and forth saving items to the AvailableItemsViewController until I go back to the navigation root. (The AvailableItemsViewController gets deallocated).

After this if I drill back down to the third controller and try to save I get this:

Here's my error (zombies enabled:)

-[AvailableItemsViewController controllerWillChangeContent:]: message sent to deallocated instance 0x1f6500

and without zombies

-[__NSArrayM controllerWillChangeContent:]: unrecognized selector sent to instance 0x4ecdee0

(i've gotten a lot of different random output on this, it seems that the destination of the controllerWillChangeContent: message is random)

all controllers are setting their properties to nil and releasing ivars in viewDidUnload and dealloc respectively.

When stepping through the crash happens at [self.managedObjectContext save:&error] in the third controller (CreateNewItemViewController)


As mentioned above, make sure your FRC is not leaking. However, if the problem persists, set the FRC delegate to nil in your controller's dealoc. This will disable change tracking and prevent calls to your deallocated VC.


You're leaking the NSFetchedResultsController. This means that it stays alive, and when something changes the data store it does its job and tries to signal the change. But since the delegate has been deallocated, you get EXC_BAD_ACCESS or messages sent to whatever random object happens to have been allocated at that memory location.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜