dispatch_once
call causes crash (in simulator) after I've converted my project to ARC.
My original problem was that I've got EXC_BAD_ACCESS
(in objc_retain call) crash in one of my singleton object's + (SingletonClass)shared { ... dispatch_once(..., ^{}); ... } method exactly one line before the dispatch_once call.
Based on loggings, and breakpoints my code have not run into the dispatch_once call's block.
I didn't know the reason, so I've just commented out the dispatch_once call. My app haven't crashed without that call.
After that I've tried to put dispatch_once in a method that my app calls earlier. Based on that I know that Xcode points to the line that is exactly before the dispatch_once call regardless of the method where the dispatch_once call is.
The main thing that is a mystery for me is that this is only reproducible if I run the app in the simulator. Running the app on a device work wihtout any problem.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSLog(@"I will crash if you won't delete the dispatch_once after me and you run me in the iOS Simulator... If you run me on a device there won't be any problem with me...");
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
int a = 42;
});
return NO;
}