Do I need to free the NSArray returned by sortedArrayUsingDescriptors?

The documentation for sortedArrayUsingDescriptorsindicates that it returns a copy of the receiving array.

What does this mean regarding the number of returned objects?

Does it need to be released?

+3
source share
3 answers

“Copy” here means an array with the contained pointers copied. This is a different array from the one who receives this message, so its account counter is completely different from the original. It is also auto-implemented because the name of the method does not contain any words “new”, “copy”, “save”, “highlight” or “init”.

+7
source

, , -sortedArrayUsingDescriptors:, . , , . , .

+2

You do not need to worry about the leak here. He says the copy tells you that this is not the same array that is sorted, but the whole object of the new array.

+1
source

All Articles