Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need to release an NSArray returned by sortedArrayUsingDescriptors?

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

What does this mean with regards to the returned object's retain count?

Do I need to release it?

like image 716
Ovesh Avatar asked Mar 02 '26 05:03

Ovesh


2 Answers

"Copy" here means an array with its contained pointers copied. It's a different array from the one receiving that message, so its retain count is entirely different from the original. It's also autoreleased as the method name doesn't contain any of the words "new", "copy", "retain", "alloc" or "init".

like image 187
BoltClock Avatar answered Mar 04 '26 18:03

BoltClock


You don't need to care whether the array you get from -sortedArrayUsingDescriptors: is autoreleased or not. What matters is whether you have copied, retained, or allocated it. If not, then don't release it.

like image 32
NSResponder Avatar answered Mar 04 '26 17:03

NSResponder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!