gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: using autorelease in apple's CF


From: Alexey Perevalov
Subject: RE: using autorelease in apple's CF
Date: Wed, 13 May 2015 11:39:03 +0300



> Subject: Re: using autorelease in apple's CF
> From: address@hidden
> Date: Wed, 13 May 2015 08:52:35 +0100
> CC: address@hidden; address@hidden; address@hidden
> To: address@hidden
>
> On 13 May 2015, at 07:25, Alexey Perevalov <address@hidden> wrote:
> >
> > right now it's more clear, I think, due CF function is not automatically put bridged(or not) objects into autorelease pool, e.g. CFStreamCreatePairWithSocket,
> > client should release it manually, like in https://github.com/robbiehanson/CocoaAsyncSocket/blob/master/GCD/GCDAsyncSocket.m with readStream/writeStream.
>
> There are some grey areas. Apple has now marked up most (all?) of their CF APIs with ARC-compatible annotations indicating ownership transfer, so >if you use CF APIs from an Objective-C compilation unit compiled with ARC then you don't need to worry about memory management - ARC will handle >it for you. I don't believe that these annotations have made it into GNUstep's CoreBase (CF implementation).

If I truly understand, to place object into autorelease pool need to send autorelease message [object autorelease], it will release ownership from client code,
in details, it just send addObject of AutoreleasePool instance, it puts object into pool.

In my implementation, for example of CFString,
CFStringRef CFStringCreateWithCString(CFAllocatorRef allocator, const char *cString, CFStringEncoding encoding){
   return ToCFString([[NSString allocWithZone:NULL] initWithCString:cString encoding:convertCFEncodingToNSEncoding(encoding)]);
}

Just NSString is created, and initWithCString is not calling autorelase, but stringWithCString is calling it.
So if in CFStringCreateWithCString just send autorelease for newly created object, no need to warry about releasing it in client code,
in case of client is ARC enabled.

>
> David
>
> -- Sent from my brain
>

reply via email to

[Prev in Thread] Current Thread [Next in Thread]