开发者

After using an NSArray *sort* method, am I responsible for releasing the returned array

开发者 https://www.devze.com 2022-12-20 07:07 出处:网络
Im used to c programming where im responsible for freeing everything, and this objective c funky stuff is throwing some spanners in the work. I am usi开发者_如何学运维ng the below code.

Im used to c programming where im responsible for freeing everything, and this objective c funky stuff is throwing some spanners in the work. I am usi开发者_如何学运维ng the below code.

NSArray *b = [a allObjects];
NSArray *c = [b sortedArrayUsingDescriptors:sortDescriptors];

Who's responsible for releasing "b" and "c". For the record, "a" is a NSSet. If I release them manually it seems to crash the app, but I'm not 100% sure so I thought Id ask.

Thanks.


Both of those calls return autoreleased objects, so you're safe. They'll be deallocated for you (sometime in the future, at the end of the current run loop for example).

The general rule is that if you don't explicitly call retain, alloc, or one of the object's copy methods, you get an autoreleased object back from whatever method you're calling.

Here is a link to the memory management documentation.

0

精彩评论

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