On May 12, 2012, at 1:55 PM, Dave Fernandes <[email protected]> wrote:
> So when a method is declared __attribute__ ((objc_returns_inner_pointer)),
> then LLVM tracks regular pointers like it would NSObject pointers to see when
> the owning object can be dealloced? Just want to make sure I understand.
In theory, the definition of objc_returns_inner_pointer allows ARC to track the
returned pointer and release the owning object after the returned pointer is no
longer used.
In the current implementation, ARC simply retains and autoreleases the owning
object and makes no attempt to track the returned pointer.
You can suppress the extra retain/autorelease by using objc_precise_lifetime:
void *bytes;
{
NSMutableData *obj __attribute__((objc_precise_lifetime)) = ...;
// ARC preserves obj's strong reference until variable obj goes out of
scope.
bytes = [obj mutableBytes];
// Because obj is marked precise-lifetime, ARC does not
retain/autorelease the NSData object here.
*bytes++;
// bytes remains valid here without adding autorelease overhead
}
// bytes may be invalid here because obj is no longer in scope.
--
Greg Parker [email protected] Runtime Wrangler
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]