• 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
Understanding CFMakeCollectable (was: EXC_BAD_ACCESS when -fobjc-gc)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Understanding CFMakeCollectable (was: EXC_BAD_ACCESS when -fobjc-gc)


  • Subject: Understanding CFMakeCollectable (was: EXC_BAD_ACCESS when -fobjc-gc)
  • From: Gabriel Zachmann <email@hidden>
  • Date: Wed, 7 Oct 2009 23:48:10 +0200

Thanks for your response.

No. CFRetain & CFRelease continue to work the same regardless of GC. That is, the reference count field still exists, but Obj-C objects in GC start life with a 0 retain count and -retain/-release/- retainCount/-autorelease are no-op'd. CF objects still start life with a retain count of 1, and thus you need to release them in order for them to participate in GC.

So in other words, the purpose of CFMakeCollectable() is to decrease the ref-count to 0 in the GC world, and only there, is that correct?


Since you do not want to release them in a ref counted environment, CFMakeCollectable (and NSMakeCollectable) need to do nothing in ref- counted (or your objects would vanish) and CFRelease (not -release) in a GC environment.

So, when I have old code like this:

    CFTypeRef obj = CFCreateType( ... );
    // do something with obj
    CFRelease( obj );

I always need to transform it into this:

    CFTypeRef obj = CFCreateType( ... );
    // do something with obj
    if ([NSGarbageCollector defaultCollector] == NULL )
        CFRelease( obj );
    CFMakeCollectable( obj );

Or does CFMakeCollectable() always have to be used like this?

    CFTypeRef obj = CFMakeCollectable( CFCreateType( ... ) );

That always gives those warnings about qualifiers ...


Regards, Gabriel.


Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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

  • Follow-Ups:
    • Re: Understanding CFMakeCollectable (was: EXC_BAD_ACCESS when -fobjc-gc)
      • From: Clark Cox <email@hidden>
    • Re: Understanding CFMakeCollectable (was: EXC_BAD_ACCESS when -fobjc-gc)
      • From: Dave Carrigan <email@hidden>
    • Re: Understanding CFMakeCollectable (was: EXC_BAD_ACCESS when -fobjc-gc)
      • From: Michael Ash <email@hidden>
    • Re: Understanding CFMakeCollectable (was: EXC_BAD_ACCESS when -fobjc-gc)
      • From: Shawn Erickson <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>)

  • Prev by Date: Re: feeble anti-aliasing
  • Next by Date: Autorelease pool
  • Previous by thread: Re: EXC_BAD_ACCESS when -fobjc-gc is on (Was: Memory corruption ...)
  • Next by thread: Re: Understanding CFMakeCollectable (was: EXC_BAD_ACCESS when -fobjc-gc)
  • Index(es):
    • Date
    • Thread