• 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: CGImageRef as a property of a cocoa object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CGImageRef as a property of a cocoa object


  • Subject: Re: CGImageRef as a property of a cocoa object
  • From: Uli Kusterer <email@hidden>
  • Date: Thu, 26 Sep 2013 02:14:31 +0200

On 22 Sep 2013, at 22:44, Kyle Sluder <email@hidden> wrote:
> You're both wrong. CGImageRelease is documented to be functionally equivalent to CFRelease, except for the non-NULL requirement.
>
> The reason you can call CGImageRelease with a NULL argument is simply because it doesn't do any dispatch. CFRelease dispatches through the vtable of the object you hand it without checking for NULL.
>
> I prefer to call the more specific release if I know the type of the thing I'm releasing.

As far as I’ve been informed, there are two reasons why certain APIs have a specialized version of retain/release:

1) They weren’t CFTypes on Mac OS 9 or earlier OS X releases, and were only later turned into CFTypes.

2) Apparently some members of the CoreFoundation team argue that checking for NULL is inefficient and thus insist on CFRetain/CFRelease crashing on NULL so people notice when they’re not writing proper code. People on other teams disagree, and thus write their own versions of retain/release calls that *do* check for NULL to save themselves the pain.

In any case, as long as a type is documented as being a CFType, toll-free bridged to a Cocoa type or their retain/release calls are documented as being equivalent to CFRetain/CFRelease, calling the latter is safe (but check for NULL). If not, treat them as if they’re not CFTypes, because they definitely don’t fulfil the contract. Don’t put non-CFTypes in arrays/dictionaries unless you’re providing your own retain/release callbacks.

Anyway, pretty much everything these days is a CFType, so using the dedicated retains/releases in favor of CFRetain/CFRelease (or Cocoa’s -retain/-release) is not necessary.

Cheers,
-- Uli Kusterer
“The Witnesses of TeachText are everywhere...”
http://zathras.de


_______________________________________________

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: CGImageRef as a property of a cocoa object
      • From: Uli Kusterer <email@hidden>
References: 
 >CGImageRef as a property of a cocoa object (From: Kevin Meaney <email@hidden>)
 >Re: CGImageRef as a property of a cocoa object (From: Roland King <email@hidden>)
 >Re: CGImageRef as a property of a cocoa object (From: Dave <email@hidden>)
 >Re: CGImageRef as a property of a cocoa object (From: Graham Cox <email@hidden>)
 >Re: CGImageRef as a property of a cocoa object (From: Ed Wynne <email@hidden>)
 >Re: CGImageRef as a property of a cocoa object (From: Kyle Sluder <email@hidden>)

  • Prev by Date: Re: Silent Self-Caught Exceptions vs. "All Exceptions" Breakpoint
  • Next by Date: Re: NSValidatesImmediatelyBindingOption confustication
  • Previous by thread: Re: CGImageRef as a property of a cocoa object
  • Next by thread: Re: CGImageRef as a property of a cocoa object
  • Index(es):
    • Date
    • Thread