Re: CF autorelease?
Re: CF autorelease?
- Subject: Re: CF autorelease?
- From: Wade Tregaskis <email@hidden>
- Date: Thu, 23 Apr 2009 18:56:09 -0700
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 (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