On Dec 14, 2011, at 7:42, Jens Alfke wrote:
On Dec 13, 2011, at 10:33 PM, Jerry Krinock wrote:
I think that Warning #1 is spurious because I'm releasing an object which was obtained from a 'Copy' method, which is correct. And Warning #2 is spurious because the method has 'Copy' in its name, therefore returning a retained object is expected.
I think the rules are about methods whose names *begin* with “copy” or “mutableCopy”. So the static analyzer doesn’t recognize your methods as being copiers.
This is correct. It is true that the memory management rules documentation says 'contains "copy"',
but the documentation is wrong. Compare for instance -[NSArray initWithArray:copyItems:], which does not implicitly retain even though it contains "copy" in its name. (Somehow Apple does not agree with me on this very obvious and simple logic. And don't say copyItems is about the items, because the docs don't say that I should do some English linguistic analysis of the method names, and I am sure that the compiler also doesn't.)
So here is the relevant sentence in the docs as it *should* be:
You take ownership of an object if you create it using a method whose name begins with “alloc”, “new”, “copy”, or “mutableCopy” (for example, alloc, newObject, or mutableCopy), or if you send it a retain message.
(I am not 100% sure there are not more "copy" variants, but this covers the behavior of every method in the standard Cocoa frameworks. And also the docs don't very clearly define the term "create" in this sentence; compare for instance the documentation on the method -newDocument: for some nice logical inconsistency/contradiction.)
As a general rule, when practice contradicts the documentation, than probably the documentation is wrong.
Always better to follow the (real) rules, especially when there is no good reason not to. And "the name doesn't sound very nice to me" is not a good (enough) reason.