Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looking for examples of valid Objective-C ARC code that crashes at runtime [closed]

To better understand ARC I'm looking for example code that compiles perfectly with ARC enabled , but crashes at runtime. Ie the common pitfalls that may be overlooked and can cause you a debugging nightmare if you've never encountered that issue before.

Real life examples tuned down to the minimum code that reproduces the issues would be very helpful. In particular if the ARC code is interfacing with C or C++ code.

like image 763
LearnCocos2D Avatar asked Oct 19 '11 22:10

LearnCocos2D


1 Answers

Quick example of the many 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);

Would over-release supportedInterfaces since __bridge_transfer retains the NSArray while releasing the CFArrayRef. In this case either don't use the CFRelease() or use plain __bridge.

like image 150
NJones Avatar answered Nov 07 '22 16:11

NJones



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!