Re: CFDictionarySetValue and ARC
Re: CFDictionarySetValue and ARC
- Subject: Re: CFDictionarySetValue and ARC
- From: Brent Fulgham <email@hidden>
- Date: Mon, 17 Oct 2011 13:56:54 -0700
This interesting discussion reminded me of an Analyze warning I wanted
to resolve (under ARC):
On Mon, Oct 17, 2011 at 12:50 PM, Greg Parker <email@hidden> wrote:
> If you are familiar with retain/release logic then you may find that CFBridgingRetain() and CFBridgingRelease()
> make more sense than __bridge_transfer and __bridge_retained.
[...]
> __bridge cast converts id to void* or void* to id with no retain count changes.
Is there an equivalent to autorelease for CF objects?
I have a routine that creates a CFSocketRef which will later be
assigned to the member variable of an object:
==========================================================
- (CFSocketRef)createDataSocketMonitor:(int)socket
withCallback:(CFSocketCallBack)socketCallBack
ofCallBackType:(CFSocketCallBackType)cbType
{
CFSocketContext context = {0, (__bridge void*)self, NULL, NULL, NULL };
CFSocketRef runSocket =
CFSocketCreateWithNative(kCFAllocatorDefault, socket, cbType,
socketCallBack, &context);
if (!runSocket)
{
// ... Error logging, etc.
return 0;
}
CFRunLoopSourceRef rls =
CFSocketCreateRunLoopSource(kCFAllocatorDefault, runSocket, 0);
if (!rls)
{
// ... Error logging, etc.
CFSocketInvalidate(runSocket);
CFRelease(runSocket);
return 0;
}
CFRunLoopAddSource(CFRunLoopGetCurrent (), rls, kCFRunLoopDefaultMode);
CFRelease(rls);
return runSocket;
}
==========================================================
LLVM complains here that runSocket leaves with a +1 state, and might
be leaked. However, I'm pretty sure I don't want to release inside
this method because the socket might get cleaned up before my caller
can CFRetain the return value.
Is there a better approach to returning a CoreFoundation type from a
routine like this?
Thanks,
-Brent
_______________________________________________
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