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 PROTECTED] 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 (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 [EMAIL PROTECTED]

Reply via email to