Update: Tidied up question and made it a bit clearer
I am getting EXC_BAD_ACCESS crashes on a NSManagedObject.
I have a Sentence managed object that I pass to a modal view (addStoryItem) like so:
addStoryItem.sentence = (Sentence*)[fetchedResultsController objectAtIndexPath:indexPath];
AddStoryItem is set to retain Sentence:
@property (retain) Sentence *sentence;
Sometimes the user needs to do something that shows another modal (on top of addStoryItem) – which doesn’t affect this object, but it does take a copy of a NSMutableSet – sentence.audiosets
If I they do view this modal I get an EXC_BAD_ACCESS whenever I try to access or set the sentence object or its properties, once the user is returned to addStoryItem
- There is a current managed object context & fetched results controller
- everything works fine unless I show that modal view controller (which, afaik, doesn’t have anything to do with the sentence object)
- Zombies is on, but it doesn’t tell me anything (BRAINS?)
Here’s a simple summary of what goes on:
- user selects row in tableview
- I get object from table and set the modal’s sentence property then display the modal with the fetchedResultsController
- I display a string, image and set a nsset from the sentence to ui aspects of the modal
- if the user needs to modify the nsset they display another modal, with a copy of the first nsset (which doesn’t change or access the sentence object)
- if I try to set a property in the sentence after closing the 2nd modal (or NSLOG sentence) –
EXC_BAD_ACCESS.
As far as I’m concerned I own sentence. Other properties of addStoryItem are still hanging around in memory – but sentence isn’t there when I try to get to it. Yes, I release sentence in addStoryItem’s dealloc – but that’s not being called (I have a log statement in there).
Can you help? Happy to provide more code or info. Pretty frustrated!
You are creating a new
sentenceToUpDatein yourdidSelectRowAtIndexPath:. Surely, this reference will be forgotten as soon as you are out of that method.Rather, you should assign the retrieved object to your retained property, like this:
Now the instance should be retained as expected.
Another possible culprit is your copy of the
NSSet. Try creating a newNSSetto make sure you are not effecting the entity: