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

Re: autorelease CGImageRef?


  • Subject: Re: autorelease CGImageRef?
  • From: Peter N Lewis <email@hidden>
  • Date: Thu, 7 Aug 2008 10:44:52 +0800

At 7:48 AM -0700 6/8/08, Shawn Erickson wrote:
Likely best to point folks at the documentation...

<http://developer.apple.com/documentation/Cocoa/Conceptual/GarbageCollection/Articles/gcCoreFoundation.html>

Yes, that is quite helpful (except that the imagined implementation of CFMakeCollectable omits the fact that it is a no-op in managed memory mode).


This email sent to email@hidden 2:26 PM +0200 6/8/08, Jean-Daniel Dupas wrote:
If I'm not wrong, it should be something like this:

[NSMakeCollectable(aCGImageRef) autorelease];

This appears correct, except for the fact that, for reasons known only to Apple, although CFMakeCollectable is available in 10.4, the trivial NSMakeCollectable macro is available only in 10.5. So expanding the NSMakeCollectable macro gives:


return [(id)CFMakeCollectable(aCGImageRef) autorelease];

However, the working of this line of code is rather subtle.

In memory managed mode CFMakeCollectable is a no-op and autorelease works, so the code is equivalent to

return [(id)aCGImageRef autorelease];

while in garbage collected mode, CFMakeCollectable is equivalent to CFRelease, and autorelease is a no-op, so the code is equivalent to:

CFRelease(aCGImageRef);
return (id)aCGImageRef

The documentation is well worth readings because it is quite tricky the way CFRetain/CFRelease always work, even in garbage collection mode, and CFRetainCount > 0 stops garbage collection from happening on the object, while retain/release/autorelease work only in memory managed mode and are no-ops in garbage collection mode (that part is well known I think).

Thanks for the enlightenment!
   Peter.
--
              Keyboard Maestro 3 Now Available!
                Now With Status Menu triggers!

Keyboard Maestro <http://www.keyboardmaestro.com/> Macros for your Mac
<http://www.stairways.com/>           <http://download.stairways.com/>
_______________________________________________

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: autorelease CGImageRef?
      • From: Chris Hanson <email@hidden>
    • Re: autorelease CGImageRef?
      • From: "Sean McBride" <email@hidden>
References: 
 >Re: autorelease CGImageRef? (From: Mike Abdullah <email@hidden>)
 >Re: autorelease CGImageRef? (From: Jean-Daniel Dupas <email@hidden>)
 >Re: autorelease CGImageRef? (From: Negm-Awad Amin <email@hidden>)
 >Re: autorelease CGImageRef? (From: "Shawn Erickson" <email@hidden>)

  • Prev by Date: Re: How to use a button to update an application with a text field value
  • Next by Date: Re: How to use a button to update an application with a text field value
  • Previous by thread: Re: autorelease CGImageRef?
  • Next by thread: Re: autorelease CGImageRef?
  • Index(es):
    • Date
    • Thread