objective c - mutableCopy memory leak -
can shed light why use of mutablecopy leaking memory?
- (id)objectinlistatindex:(unsigned)theindex { nssortdescriptor *descriptor = [[[nssortdescriptor alloc] initwithkey:@"notenumber" ascending:yes] autorelease]; [list sortusingdescriptors:[nsarray arraywithobjects:descriptor,nil]]; nsmutablearray *thearray = [list mutablecopy]; nsdictionary *thedict = [thearray objectatindex:theindex]; return thedict; }
because mutablecopy
returns retained object, , never release thearray
.
copy methods return retained object caller responsible releasing. detailed in api docs , memory management guide.
Comments
Post a Comment