On Wed, Oct 7, 2009 at 3:09 PM, Dave Carrigan <d...@rudedog.org> wrote: > > For new code, the typical pattern is > > CFTypeRef obj = CFMakeCollectable(CFCreateType(…)); // no-op in > non-gc; releases and makes eligible for collection in gc > // ... > if ([NSGarbageCollector defaultCollector] == NULL) CFRelease(obj); // > releases in non-gc only
No need to do the check yourself. If you're in pure-C code, just do: CFTypeRef obj = CFCreateType(…); // ... CFRelease(obj); In this case, you gain nothing by using CFMakeCollectable, as the variable obj will keep your object rooted until after the CFRelease anyway (as it will still exist on the stack or in a register). If you're in Obj-C code, just do: CFTypeRef obj = CFMakeCollectable(CFCreateType(…)); // no-op in non-gc; releases and makes eligible for collection in gc [(id)obj autorelease];//releases in non-gc only // ... Or: CFTypeRef obj = CFMakeCollectable(CFCreateType(…)); // no-op in non-gc; releases and makes eligible for collection in gc // ... [(id)obj release];//releases in non-gc only -- Clark S. Cox III clarkc...@gmail.com _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com