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.
精彩评论