I don’t seem to understand that. I have a method that returns a volatile array. What is the correct way to return an array and avoid possible memory leaks?
If I plan to store the results locally inside another view controller, does this affect the way the array is returned?
Finally, what if it's just not a mutable array? Does this require a different technique?
thanks howie
, - . , , .
- (NSMutabalArray*] mutableArray { return [[myArray mutableCopy] autorelease]; } - (NSArray*] array { return [[myArray copy] autorelease]; }
. alloc/init/copy, autorelease , (- return [myArray autorelease];). , factory (arrayFrom... arrayWithContentsOf...), , .
return [myArray autorelease];
arrayFrom...
arrayWithContentsOf...
apple dev. , , .
NSMutableArray :
-(NSMutableArray*)getMyArray { NSMutableArray *retval = [[NSMutableArray alloc] init]; // do your stuff w/ array return [retval autorelease]; }
The caller of this code may want the retainreturned array because it is auto-implemented.
retain
Source: https://habr.com/ru/post/1737939/More articles:How to configure SQL LIKE function? - sqlNewbie question: creating a custom control - asp.netParsing a 2-dimensional JSON array in Javascript - jsonЗагрузка OverlayView из XIB -vs- программно для использования с UIImagePickerController - objective-cHow to create processing events for a TextBox array - c #How to show onfocus header attributes using jquery? - jqueryWhere can I get streaming (live) video and audio from the application for the camera example for Nokia? - javaORM для PHP - проблема с производительностью - phpLifecycle prerequisite for maven plugin execution? - javaBSD Sockets do not work in iPhone 3G environment - iosAll Articles