Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 changed since this is one of the base foundations of Memory Management for iOS.

Does anybody know why? Thanks!

like image 255
LaN Avatar asked Apr 04 '11 03:04

LaN


1 Answers

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.

like image 84
BJ Homer Avatar answered Sep 18 '22 03:09

BJ Homer