Something I've been using as of late to make CF a little more bearable is the cleanup attribute offered by gcc, e.g.:

static inline void _autoreleaseCFArray(CFArrayRef *array) {
        if (NULL != *array) {
                CFRelease(*array);
        }
}

#define CFAutoreleasedArrayRef __attribute__((cleanup(_autoreleaseCFArray))) CFArrayRef

Unfortunately there's an apparent bug in gcc that requires you to have exact type matches, so you can't make e.g. a generic CFTypeRef variant (unless your variables really are declared as CFTypeRefs). But still, if you're using a particular set of objects a lot, it can save you so much work.

Don't be confused by the terminology, though; this'll only "autorelease" whatever's assigned to that variable when it goes out of scope. If you modify the pointer or clear it, you won't get that autorelease. For simple uses this is fine, I find. If your background is predominately C++ you might be more comfortable with an "Auto" naming scheme instead.

Wade
_______________________________________________

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