1
votes

I am currently working on an app that heavily relies on Core Data. I use a navigation controller to push and pop views around. When I go back in the stack in the navigation controller the program sometimes crashes and I receive the error (usually highlighted on a managedObjectContext synthesize or dealloc):

"Thread 1: Program received signal: "EXC_BAD_ACCESS".

I used the static analyzer to fix all the leaks it found.

I used NSZombie and it seems like my allocations go up, and then do not go down as I pull the menu views off. Then when I click on another menu view I get two results.

0 Category:NSManagedObjectContext EventType:Malloc RefCt:1 Timestamp:00:04.133.722 Address:0x5da0f10 Size:128 RespLib:pua-app RespCaller:-[pua_appAppDelegate managedObjectContext]

1 Category:NSManagedObjectContext EventType:Zombie RefCt:-1 Timestamp:00:16.524.983 Address:0x5da0f10 Size:0 RespLib:pua-app RespCaller:-[OpenersroutinesMenuViewController setManagedObjectContext]

I have ZERO experience with this type of debugging, but apparently the managed object context is 'unhappy' and my guess is that I am not properly creating or managing the context as it is passed through the menu. This is also interesting because the MOC is not being altered in these menus, and in the views where it is modified this error does not occur.

1
Be sure to add an answer with your solution so that others can learn from it and, perhaps more importantly, no one else will try to answer it. :)Matthew Frederick

1 Answers

1
votes

First, leaks will never cause this kind of crash. A leak is an under-release. These crashes are generally cause by an over-release.

From your NSZombie output, it looks like your MOC is the thing being over-released. I would look at each place you handle a managedObjectContext and make sure that you retain and release it correctly. The first rule is to use accessors rather than messing with your ivars directly (except in -init, -dealloc and your accessors, which should use the ivars).

A possible cause of this kind of issue is multi-threading. Make sure that you're not accessing the same MOC from multiple threads. They're not thread-safe.

The issue probably has nothing to do with the views or the menus. The problem is most likely that you're calling -release on a MOC that you did not retain.