views:

48

answers:

4

Can you describe the naming convention difference between a method that returns an object it has allocated for the caller (and that the caller should release), and a method that returns an autorelease object?

+5  A: 

Methods that return a retained object (which the caller should release) should include the word copy, new, mutableCopy, or alloc (as in an alloc/init pair). Everything else should return an autoreleased object.

mipadi
+3  A: 

Did you have a look atApple's documentation?

Tim
+1  A: 

If the method has alloc, new, copy or create in the name, it will return a new, retained object, by convention.

kubi
A: 

According to this:

  1. methods that start with -allocXXX or -newXXX, or contains the word "copy" will/should return an allocated object
  2. any method that doesn't follow rule #1 will/should return an autoreleased object
Yahya Cahyadi