• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Understanding CFMakeCollectable (was: EXC_BAD_ACCESS when -fobjc-gc)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >Re: EXC_BAD_ACCESS when -fobjc-gc is on (Was: Memory corruption ...) (From: Gabriel Zachmann <email@hidden>)
 >Re: EXC_BAD_ACCESS when -fobjc-gc is on (Was: Memory corruption ...) (From: David Duncan <email@hidden>)
 >Understanding CFMakeCollectable (was: EXC_BAD_ACCESS when -fobjc-gc) (From: Gabriel Zachmann <email@hidden>)
 >Re: Understanding CFMakeCollectable (was: EXC_BAD_ACCESS when -fobjc-gc) (From: Dave Carrigan <email@hidden>)

  • Prev by Date: View Hierarchies for apps like Quartz Composer
  • Next by Date: Reacting to UIBarButtonItem
  • Previous by thread: Re: Understanding CFMakeCollectable (was: EXC_BAD_ACCESS when -fobjc-gc)
  • Next by thread: Re: Understanding CFMakeCollectable (was: EXC_BAD_ACCESS when -fobjc-gc)
  • Index(es):
    • Date
    • Thread