I have using blocks and ARC, and found in some situation, iOS only crash in Release build. It was wrong way to write code, like this.
-(IBAction)clickedButtonA:(UIBarButtonItem*)sender event:(UIEvent*)event {
NSMutableArray *arrRows = [NSMutableArray arrayWithCapacity:0];
#warning this code only crash on Release Build.... Don't use this
NSMutableDictionary * dicRow = [NSMutableDictionary dictionaryWithCapacity:0];
[arrRows addObject:dicRow];
dispatch_block_t block = ^{
NSString *str = [NSString stringWithFormat:@"%@",[_tweet valueForKey:@"text"]];
[[UIPasteboard generalPasteboard] setString:str];
};
[dicRow setValue:block forKey:kDicKeyLinkPopBlock];
NSMutableArray *sections = [NSMutableArray arrayWithObject:arrRows];
TOVLinkPopoverViewController *controller= [[TOVLinkPopoverViewController alloc] init];
controller.arrayLink = sections;
}
And from other controller, when I access the block, it crashes only I am on release build. I have learn you need to copy the block
[dicRow setValue:[block copy] forKey:kDicKeyLinkPopBlock];
For non-block aware Class like NSMutableDictionary.
The question is "Why it only crashes on Release build?" I know this "should crash", and this was wrong way of using block, but hoping it crashes on Debug build so we can find this kind of bug earlier.
One more question is "Is there any build setting that makes this code crash with debug build?"
You can ran sample code from gitHub, https://github.com/tomohisa/iOS_PopoverMenu_Notification
See ViewController.m and find commented out code (only crash on release).