Re: Guidelines for Cocoa frameworks supporting garbage collection?
Re: Guidelines for Cocoa frameworks supporting garbage collection?
- Subject: Re: Guidelines for Cocoa frameworks supporting garbage collection?
- From: Bill Cheeseman <email@hidden>
- Date: Sun, 06 Jul 2008 08:41:47 -0400
- Thread-topic: Guidelines for Cocoa frameworks supporting garbage collection?
on 2008-07-06 2:04 AM, mmalc crawford at email@hidden 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@hidden
Quechee Software, Quechee, Vermont, USA
www.quecheesoftware.com
PreFab Software - www.prefabsoftware.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