On Thu, Apr 23, 2009 at 9:56 PM, Wade Tregaskis <wadesli...@mac.com> wrote:
> 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. > Another caveat with cleanup is that it is not guaranteed to be called. For this audience, the most likely way this will bite you is when the new zero cost objective-c exceptions aren't available (i386, ppc) and an exception is thrown. If zero cost objective-c exceptions are available, then the compiler arranges to have the cleanup function called during the stack unwind. There's enough gotchas to cleanup that I definitely wouldn't count on it for proper memory management. _______________________________________________ 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