• 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
Re: CF autorelease?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: CF autorelease?
      • From: Peter N Lewis <email@hidden>
    • Re: CF autorelease?
      • From: John Engelhart <email@hidden>
References: 
 >CF autorelease? (From: Todd Heberlein <email@hidden>)
 >Re: CF autorelease? (From: Michael Ash <email@hidden>)

  • Prev by Date: Snow Leopard DevForums Now Available
  • Next by Date: Re: Long Time Dealy When getting Vended Object
  • Previous by thread: Re: CF autorelease?
  • Next by thread: Re: CF autorelease?
  • Index(es):
    • Date
    • Thread