I'm getting an intermittent bug that is proving very hard to debug.
I'm getting the following error from the following method
EXC_BAD_ACCESS(code=1, address=0x10) on Core Data Fetch
class func getAll(context: NSManagedObjectContext) -> [Tag] {
var returnValue: [Tag] = []
do {
let fetchRequest = NSFetchRequest(entityName: Tag.entityName())
returnValue = try context.executeFetchRequest(fetchRequest) as! [Tag]
} catch {
}
return returnValue
}
The bug is extermely intermittent, and is only happening on every few 100 sessions, but is appearing frequent enough that I need to deal with it. The code breaks on the line returnvalue = try context.execute...
fetchRequest
is not nil
context
is not nil
I've turned on the NSZombieFlag to try to see if some memory is deallocated somewhere and then being accessed, but I'm stumped on what is causing this. Any ideas or insight would be much appreciated.
EXC_BAD_ACCESS means that message was sent to a point in the memory where there's no instance of a class to execute it. Thus “bad access”. You will get EXC_BAD_ACCESS in 3 cases: An object is not initialized.
To debug an EXC_BAD_ACCESS, you can generally find out the where the dangling pointer is by enabling zombie objects. Choose edit scheme, then Diagnostics tab in the Run section, then click the 'Zombie Objects' option. Another cause for EXC_BAD_ACCESS can be infinite recursion, which can be found by adding some logging.
Almost all EXC_BAD_ACCESS issues I've seen with Core Data are caused by trying to use thread concurrency instead of the newer queue concurrency model.
Since iOS 5 you are required to use performBlock
or performBlockAndWait
when accessing a managed object context.
https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CoreData/Concurrency.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With