• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: CFDictionarySetValue and ARC
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CFDictionarySetValue and ARC


  • Subject: Re: CFDictionarySetValue and ARC
  • From: Kyle Sluder <email@hidden>
  • Date: Mon, 17 Oct 2011 14:16:04 -0700

On Mon, Oct 17, 2011 at 1:56 PM, Brent Fulgham <email@hidden> wrote:
> 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?

Your method should be named -newDataSocketMonitor:... since you are
handing off a +1 reference to the caller. The caller can then deal
with the object as appropriate.

--Kyle Sluder
_______________________________________________

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

References: 
 >CFDictionarySetValue and ARC (From: Roland King <email@hidden>)
 >Re: CFDictionarySetValue and ARC (From: Greg Parker <email@hidden>)
 >Re: CFDictionarySetValue and ARC (From: Brent Fulgham <email@hidden>)

  • Prev by Date: Re: CFDictionarySetValue and ARC
  • Next by Date: Re: NSArrayController Update Delay
  • Previous by thread: Re: CFDictionarySetValue and ARC
  • Next by thread: Arcs and Bridges
  • Index(es):
    • Date
    • Thread