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 (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

Reply via email to