Here I would like to share my experience in successfully solving out a crash while playing around with core data entities using xcode instruments.
The implementation is straight forward. I have one entity “MyApp”, having one attribute “newName”. In viewWillAppear I just create the entity, assign a value to the attribute, do a save and finally do a fetch.
Things were fine until save. But when I printed the fetched result , the THING happened. A crash….
This was all I got. No console logs, no warnings, no murder weapons.
The initial clues were EXC_BAD_ACCESS and EXC_1386, indicating the presence of it, yes, the ZOMBIE. Zombies are objects having retain count 0 still continuing to exist. To confirm it enable zombies in product -> Edit Schemes -> Diagnostics , enable the check mark for Zombie objects.
Running the app again, I got the logs. Cause of crash due to a string zombie object.
It’s time to find the zombie.
In order to dig deeper we need the help of detective “xcode instruments”. Open xcode ->developer tools -> instruments -> select zombie
Select the desired simulator and app in the scheme and tap the red record button.
Boom we get this zombie found pop up,
Seeing the allocation history, I could find that after the fetch, accessing the attribute “newName” caused the memory release of the property,
But why ? what’s the motive ?
ARC imposes a constraint on method naming:
- You cannot give an accessor a name that begins with
Case is solved, renaming the attribute of the core data entity from “newName” to “updatedName “solved the crash.
Hope this helps you. Any help feel free to reach me at firstname.lastname@example.org.