> Subject: Re: using autorelease in apple's CF
> From: [email protected]
> Date: Wed, 13 May 2015 08:52:35 +0100
> CC: [email protected]; [email protected]; [email protected]
> To: [email protected]
>
> On 13 May 2015, at 07:25, Alexey Perevalov <[email protected]>
> 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
>
_______________________________________________
Gnustep-dev mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/gnustep-dev