开发者

Apple changed their Memory Management Rule for Naming Convention

As stated in Cocoa Memory Management Rules from before

You take ownership of an object if you create it using a method whose name begins with “alloc” or “new” or contains “copy” (for example, alloc, newObject, or mutableCopy), or if you send it a retain message.

haven't read it after December 2010, but since has changed since then to

You “create” an object using a method whose name begins with “alloc”, “new”, “copy”, or “mutableCopy” (for example, alloc, newObject, or mutableCopy).

Notice that now, it is required to have "copy" as a prefix. This resulted to a few memory related warnings from Clang Static Analyzer :(. After searching the interwebs, I haven't got to a conclusion as to why was this开发者_StackOverflow中文版 changed since this is one of the base foundations of Memory Management for iOS.

Does anybody know why? Thanks!


There were some methods that contained "Copy" in their text, but were clearly not copying methods. For example, +[NSData dataWithBytesNoCopy:length:]. It was, of course, possible to use annotations for the static analyzer to inform about the nonstandard behavior, but in general I suspect that almost nobody (yourself excepted) ever wrote a copy method that didn't start with copy or mutableCopy, so they decided to just simplify things.

I'm glad they did, frankly, as I've run into the opposite problem, where a method contained the word "Copy" but was not intended to return an owning reference.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜