Re: A question of memory management style
Re: A question of memory management style
- Subject: Re: A question of memory management style
- From: Ken Thomases <email@hidden>
- Date: Mon, 18 Jul 2011 10:16:55 -0500
On Jul 18, 2011, at 8:18 AM, Scott Ribe wrote:
> On Jul 17, 2011, at 10:32 PM, John Brownie wrote:
>
>> [HandlerClass createHandlerWith...]
>
> I think your model is correct, but Cocoa convention is that method names beginning with create confer ownership to the caller. If the caller does not need to release the object, the method name should not be createHandlerWIthXXX, but handlerWithXXX.
That's not correct. Core Foundation's naming conventions treat "create" specially, but Cocoa's don't. This is specifically called out in the Memory Management Programming Guide
<http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html>:
> Important: There are similar memory management rules for Core Foundation objects (see Memory Management Programming Guide for Core Foundation). The naming conventions for Cocoa and Core Foundation, however, are different. In particular, Core Foundation’s “create rule in Memory Management Programming Guide for Core Foundation” does not apply to methods that return Objective-C objects. For example, in the following code fragment, you are _not_ responsible for relinquishing ownership of myInstance:
>
> MyClass *myInstance = [MyClass createInstance];
However, I agree that handlerWithXXX is a better choice.
Regards,
Ken
_______________________________________________
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