Why does using “Step over” feature in XCode debugger hide issue with weak property that ought to be strong

前端 未结 1 1559
臣服心动
臣服心动 2021-01-27 05:03

I\'ve just finished debugging an issue where an iOS Google Map (GMSMapView) showed on some devices and in some iOS version simulators, but not others. It was odd t

相关标签:
1条回答
  • 2021-01-27 05:27

    I've had issues like this before between release and debug builds. There is some difference in timing between when weak references are nilled out, presumably because the debugger is holding on to references for some reason. I don't know the details of how ARC is implemented but it seems to be a fairly consistent pattern.

    Directly assigning a newly created object to a weak reference is wrong - under the rules of ARC it would be instantly deallocated and nilled out, because nothing else has a strong reference to it.

    This is the main reason I don't like to have view or IBOutlet properties set to weak - there is no need, since views don't get unloaded any more, and it just leads to subtle bugs like this.

    0 讨论(0)
提交回复
热议问题