on 2008-07-06 2:04 AM, mmalc crawford at [EMAIL PROTECTED] wrote:

> On Jul 5, 2008, at 10:07 PM, Chris Hanson wrote:
> 
>> Can you give an example of a framework method that's documented to
>> return an autoreleased CF object?
> 
> NSBitmapImageRep:

NSEvent, too:

- (const void *)eventRef -- returns a carbon EventRef opaque type
corresponding to the receiver
- (CGEventRef)CGEvent -- returns a Core Graphics CGEventRef opaque type
corresponding to the receiver

The Leopard AppKit release notes say of the first of these "The EventRef is
retained by the NSEvent, so will be valid as long as the NSEvent is valid,
and will be released when the NSEvent is freed. You can use RetainEvent to
extend the lifetime of the EventRef, with a corresponding ReleaseEvent when
you are done with it."

The release notes say of the second: "-CGEvent ... Returns an autoreleased
CGEventRef corresonding to the NSEvent. If you want to control the lifetime
of the CGEventRef, you should retain it.

I was puzzled at first by the differing return type conventions, and by the
different phrasing of the memory management discussions. I guess, however,
from looking briefly at the Carbon Event Manager Reference, that the carbon
EventRef isn't a CFType and has a variety of memory management methods of
its own -- I've never had occasion to use it.

But they seem to present the same issues with respect to their use in a
garbage collected Cocoa application or framework.

--

Bill Cheeseman - [EMAIL PROTECTED]
Quechee Software, Quechee, Vermont, USA
www.quecheesoftware.com

PreFab Software - www.prefabsoftware.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