> Subject: Re: using autorelease in apple's CF > From: thera...@sucs.org > Date: Wed, 13 May 2015 08:52:35 +0100 > CC: i...@vucica.net; lu...@dolezel.info; gnustep-dev@gnu.org > To: alexey.pereva...@hotmail.com > > On 13 May 2015, at 07:25, Alexey Perevalov <alexey.pereva...@hotmail.com> > 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 Gnustep-dev@gnu.org https://lists.gnu.org/mailman/listinfo/gnustep-dev