EXC_BAD_ACCESS crash fixed by moving block of code onto own thread

I've been hitting my head against the wall with a strange (to me) EXC_BAD_ACCESS crash and I was wondering if any of you could help.


The short of it is I'm taking raw email data, scanning what I need, and then sending it up to Firebase. This all happens through several function calls. The initial function call is made inside of a `dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND,0)){...}` block. If I put it on the main queue crash doesn't happen. Currently, I've made the crash stop by putting the to-Firebase function on the background a second time. Obviously this is not a real solution, but I am stumped as to what the problem or type of problem could be.


The crash always seems to happen at the top of whatever function the problematic code is in. I consoldiated all the code into the dispatch_async block and the EXC_BAD_ACCESS happened at the very first line.


Sometimes it looks like it happens on an NSDateFormatter singleton.


It's currently still in Swift 2.3.

Replies

It’s hard to say what’s going on here based on the details you’ve provided so far. Most problems like this stem from sharing mutable data across threads. That’s the first thing I suggest you investigate.

If that doesn’t pan out, please post some more details, including the critical sections of the code that’s triggering the crash.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"