• 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: A question of memory management style
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: A question of memory management style
      • From: John Brownie <email@hidden>
References: 
 >A question of memory management style (From: John Brownie <email@hidden>)
 >Re: A question of memory management style (From: Scott Ribe <email@hidden>)

  • Prev by Date: Re: NSTextView won't deallocate
  • Next by Date: Re: Need help debugging this
  • Previous by thread: Re: A question of memory management style
  • Next by thread: Re: A question of memory management style
  • Index(es):
    • Date
    • Thread