bridged cast: __bridge_transfer vs __bridge with synthesized setter

后端 未结 3 2077
再見小時候
再見小時候 2020-12-30 07:43

I am using ARC, and have confusion while using __bridge_transfer. I have a property userName as following:

@property (nonatomic, re         


        
3条回答
  •  星月不相逢
    2020-12-30 08:19

    When you call ABRecordCopyCompositeName(), someone must release the returned object at some point. Using __bridge_transfer ensures that ARC will release the object for you. Without __bridge_transfer, you must release the returned object manually. Those are the only two options.

    Therefore, you must use __bridge_transfer in both cases.

    A nice exercise is to induce a leak by using __bridge instead of __bridge_transfer, then use Xcode and Instruments to try and find the leak. Does the compiler pick up the leak? Does static analysis (Project -> Analyze) pick up the leak? Does Instruments pick up the leak? If so, you'll then know how to check whether __bridge_transfer solves the problem.

提交回复
热议问题