• 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: CFNetworking and ARC (was: ARC conversion help - CFErrorRef* and NSError**)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CFNetworking and ARC (was: ARC conversion help - CFErrorRef* and NSError**)


  • Subject: Re: CFNetworking and ARC (was: ARC conversion help - CFErrorRef* and NSError**)
  • From: Roland King <email@hidden>
  • Date: Wed, 31 Oct 2012 08:27:22 +0800

On 31 Oct, 2012, at 7:59 AM, Rick Mann <email@hidden> wrote:

>
> On Oct 30, 2012, at 3:15 , Roland King <email@hidden> wrote:
>
>> how did you do it before, in non-ARC, what's the code look like? There must be a combination of CFBridgingRetain(), CFBridgingRelease() and (__bridge .. ) you can use to do what you're doing.
>
> Before, I used explicit retain and release. But now, if I CFBridgingRetain() my NSObject as I pass it into CFSocketCreateConnectedToSocketSignature() (via CFSocketContext), then I can't CFBridgingRelease() it in my CFSocketCallBack, it can (will) get over-released, because that's called multiple times. So, obviously I can't do that.
>
> The only place I can release it is when I CFRelease() the socket. But there's no way to release my object without compiler sleight-of-hand.
>
> --
> Rick
>

I must be missing something here. Why can't you just set up your CFSocketContext with CFRetain for the CFAllocatorRetainCallback, CFRelease for the CFAllocatorReleaseCallback and cast the object to the (void*)info paramter with (__bridge void*)yourObject when you put that into the CFSocketContext. Job done, the CFSocket code will call CFRetain() for you during CFSocketCreateConnectedToSocketSignature(), which will retain it before ARC releases the original, and will call CFRelease() when the socket deallocs.

You don't want CFBridgingRetain() here because you aren't passing ownership to Core Foundation, you're just giving it the object and it's taking ownership and releasing it again via the retain and release methods you've told it to use in CFSocketContext.


_______________________________________________

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

  • Follow-Ups:
    • Re: CFNetworking and ARC (was: ARC conversion help - CFErrorRef* and NSError**)
      • From: Rick Mann <email@hidden>
    • Re: CFNetworking and ARC (was: ARC conversion help - CFErrorRef* and NSError**)
      • From: Rick Mann <email@hidden>
References: 
 >ARC conversion help - CFErrorRef* and NSError** (From: Alex Kac <email@hidden>)
 >Re: ARC conversion help - CFErrorRef* and NSError** (From: John McCall <email@hidden>)
 >Re: ARC conversion help - CFErrorRef* and NSError** (From: Rick Mann <email@hidden>)
 >Re: ARC conversion help - CFErrorRef* and NSError** (From: Quincey Morris <email@hidden>)
 >Re: ARC conversion help - CFErrorRef* and NSError** (From: Rick Mann <email@hidden>)
 >Re: ARC conversion help - CFErrorRef* and NSError** (From: Roland King <email@hidden>)
 >CFNetworking and ARC (was: ARC conversion help - CFErrorRef* and NSError**) (From: Rick Mann <email@hidden>)

  • Prev by Date: Re: CFNetworking and ARC (was: ARC conversion help - CFErrorRef* and NSError**)
  • Next by Date: Re: CFNetworking and ARC (was: ARC conversion help - CFErrorRef* and NSError**)
  • Previous by thread: Re: CFNetworking and ARC (was: ARC conversion help - CFErrorRef* and NSError**)
  • Next by thread: Re: CFNetworking and ARC (was: ARC conversion help - CFErrorRef* and NSError**)
  • Index(es):
    • Date
    • Thread