Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7960211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:41:38+00:00 2026-06-04T04:41:38+00:00

I have using blocks and ARC, and found in some situation, iOS only crash

  • 0

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).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:41:39+00:00Added an answer on June 4, 2026 at 4:41 am

    You’re right that you need to add [block copy]. This is because that block is created in the current stack frame (i.e. within clickedButtonA:event:) but then you add it to a dictionary and presumably pull it out later. When you pull it out later and use it, that original stack frame has gone and you will have a pointer to some random memory that might not (most likely won’t) actually be the block any more.

    When you copy the block, if it’s on the stack currently then it gets copied to the heap and if it’s already on the heap then it just retains it. This means that you now have a block which can be passed around between contexts and will be valid.

    The reason that you are only seeing it crash in release mode is because release mode will be turning on compiler optimisation that is completely changing how the stack is handled. Probably you were very lucky in debug mode not to see the problem and was simply a quirk of how your app is designed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following error on a Ios 5 application using ARC: *** -[ViewDettaglio
I have a iOS project in which I am using ARC in my own
I have some operations that are inside blocks. This operations, only update an UIImage
I have some difficulties for using Ruby block, passing in a method. As in
I have the following block of jQuery code that I'm using to copy some
I find using blocks in some cases more convenient to use than the Delegate
I'm using ARC and targeting iOS 5. I've declared an NSMutableArray ivar in one
I am currently using blocks in my UIButton category. However I have come across
I'm using application blocks and i have a property that use a Not Null
Im trying to create a simple callback using blocks. I have a MainViewController which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.