Look for examples of valid Objective-C ARC code that crashes at runtime

To better understand ARC, I am looking for sample code that compiles fine with ARC enabled, but crashes at runtime. That is, common errors that can be missed and can cause you a debugging nightmare if you have never encountered this problem before.

Real life examples tuned for minimal code that reproduces the problems will be very helpful. In particular, if ARC code interacts with C or C ++ code.

+6
source share
1 answer

A quick example of what I was thinking along the same lines as bbum.

Casting from CF ... to NS ... confuses ARC if done incorrectly, for example:

CFArrayRef *supportedInterfaces = CNCopySupportedInterfaces(); NSArray *interfaceNames = (__bridge_transfer NSArray *)supportedInterfaces; CFRelease(supportedInterfaces); 

Will over-release be supported by Interfaces since __bridge_transfer saves NSArray when CFArrayRef is released. In this case, either do not use CFRelease (), or use the usual __bridge.

+4
source

Source: https://habr.com/ru/post/899650/


All Articles