I want to populate an array as follows:
NSMutableArray *array = [self methodThatReturnsAnArray];
In the method method of methodThatReturnsAnArray, I create an array like this:
NSMutableArray *arrayInMethod = [[NSMutableArray alloc] init];
When I finished filling in "arrayInMethod", I return the array and to prevent the memory leak that I use:
return [arrayInMethod autorelease];
However, "array" -variable is never populated. However, when you delete the "abstract" it works fine. What should I do to make sure that the returned object that I released?
EDIT
+ (NSMutableArray *)buildInstants:(NSArray *)huntsArray {
NSMutableArray *goGetObjects = [[[NSMutableArray alloc] init] autorelease];
for (int i = 0; i < [huntsArray count]; i++) {
NSDictionary *huntDict = [huntsArray objectAtIndex:i];
PHGoGet *goGet = [[PHGoGet alloc] init];
goGet.title = [huntDict objectForKey:@"title"];
goGet.description = [huntDict objectForKey:@"description"];
goGet.start = [huntDict objectForKey:@"start"];
goGet.end = [huntDict objectForKey:@"end"];
goGet.ident = [huntDict objectForKey:@"id"];
if ((CFNullRef)[huntDict objectForKey:@"image_url"] != kCFNull) {
goGet.imageURL = [huntDict objectForKey:@"image_url"];
} else {
goGet.imageURL = nil;
}
if ((CFNullRef)[huntDict objectForKey:@"icon_url"] != kCFNull) {
goGet.iconURL = [huntDict objectForKey:@"icon_url"];
} else {
goGet.iconURL = nil;
}
goGet.longitude = [huntDict objectForKey:@"lng"];
goGet.latitude = [huntDict objectForKey:@"lat"];
goGet.companyIdent = [huntDict objectForKey:@"company_id"];
[goGetObjects insertObject:goGet atIndex:i];
[goGet release];
}
return [[goGetObjects copy] autorelease];
}
source
share