Re: Understanding CFMakeCollectable (was: EXC_BAD_ACCESS when -fobjc-gc)
Re: Understanding CFMakeCollectable (was: EXC_BAD_ACCESS when -fobjc-gc)
- Subject: Re: Understanding CFMakeCollectable (was: EXC_BAD_ACCESS when -fobjc-gc)
- From: Clark Cox <email@hidden>
- Date: Wed, 7 Oct 2009 17:05:07 -0700
On Wed, Oct 7, 2009 at 3:09 PM, Dave Carrigan <email@hidden> 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
email@hidden
_______________________________________________
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