blocks and ARC - copy or crash with release build (caused by optimization level)

后端 未结 2 715
别那么骄傲
别那么骄傲 2021-02-14 16:02

I\'m using Xcode 4.3.3 and developing for iOS 5.0+. In development of an ARC iOS application, I\'ve started using blocks as a callback mechanism for asynchronous operations. T

2条回答
  •  清歌不尽
    2021-02-14 16:36

    This is a long comment on Firoze's answer.

    The document Automatic Reference Counting" section 7.5 states:

    With the exception of retains done as part of initializing a __strong parameter variable or reading a __weak variable, whenever these semantics call for retaining a value of block-pointer type, it has the effect of a Block_copy. The optimizer may remove such copies when it sees that the result is used only as an argument to a call.

    And this is the behavior I have seen.

    So if callbackBlock is a strong instance variable then ARC should copy any stack-allocated block pass in block. I.e. the Debug version was correct and the Release version is a compiler bug.

    If this is correct then you've found a compiler bug and should report it. Reporting it would not be bad either way, it should produce a definitive answer.

提交回复
热议问题