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:(
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.