I am writing code designed to work both in ARC and in the Garbage Collection section.
Here is some code that uses the Core Foundation, as it can be written specifically for ARC:
CFTypeRef ref=CFCopySomething();
This seems to be equivalent to:
CFTypeRef ref=CFCopySomething(); // At this point ref has retain count 1. id obj=(__bridge id)ref; // Now ref has retain count 2 due to assigning to strong variable under ARC. CFRelease(ref) // Now ref has retain count 1. [obj doSomething]; // ARC will release ref when done.
The advantage of the latter is that a call to CFRelease allows the GC to assemble the object. But I'm not sure about calling CFRelease after the transfer to the ARC with the destination with the bridge.
This will certainly work. Is this code ok?
source share