Re: ARC and CFType release callback
Re: ARC and CFType release callback
- Subject: Re: ARC and CFType release callback
- From: Greg Parker <email@hidden>
- Date: Tue, 19 Jun 2012 20:41:33 -0700
On Jun 19, 2012, at 8:28 PM, Dave Keck <email@hidden> wrote:
> I have a CFType (specifically a CGPattern) that uses a release
> callback to free resources, and the void* pointer passed to the
> callback is the object to be released.
>
> What's the correct way to release this void* pointer (that's really an
> NSObject subclass) under ARC? Casting it using __bridge_transfer
> doesn't seem right since the resulting expression is unused, and the
> compiler of course warns of this fact.
The right way to handle void* context parameters in ARC is usually one of these:
For one-shot contexts:
Set the void* context with CFBridgingRetain(object).
Retrieve your object with (ObjectType *)CFBridgingRelease(context).
For persistent contexts:
Set the void* context with CFBridgingRetain(object).
Retrieve your object with (__bridge ObjectType *)context.
Clean up the void* context with CFRelease(context) or (ObjectType *)CFBridgingRelease(context)
In C++ you'll need extra casts between void* and CFTypeRef.
If you're talking about the void* info parameter to CGPatternCreate, use the "persistent context" code.
--
Greg Parker email@hidden Runtime Wrangler
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden