I do not know how to fix the leak
How do I fix the leak here?
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
if(searching){
return nil;
}
NSMutableArray *tempArray = 开发者_如何学运维[[NSMutableArray alloc] init];
[tempArray addObject:UITableViewIndexSearch];
[tempArray addObject:@"A"];
[tempArray addObject:@"B"];
[tempArray addObject:@"C"];
[tempArray addObject:@"D"];
[tempArray addObject:@"E"];
[tempArray addObject:@"F"];
[tempArray addObject:@"G"];
[tempArray addObject:@"H"];
[tempArray addObject:@"I"];
[tempArray addObject:@"J"];
[tempArray addObject:@"K"];
[tempArray addObject:@"L"];
[tempArray addObject:@"M"];
[tempArray addObject:@"N"];
[tempArray addObject:@"O"];
[tempArray addObject:@"P"];
[tempArray addObject:@"Q"];
[tempArray addObject:@"R"];
[tempArray addObject:@"S"];
[tempArray addObject:@"T"];
[tempArray addObject:@"U"];
[tempArray addObject:@"V"];
[tempArray addObject:@"W"];
[tempArray addObject:@"X"];
[tempArray addObject:@"Y"];
[tempArray addObject:@"Z"];
return tempArray;
}
Any help would be appreciated.
Sam
You should be returning an autoreleased object:
return [tempArray autorelease];
When you get the temparray, release it when done by calling
[#<your var># release];
to solve your leak. Autorelease will work, but you will need to set a NSAutoRelease pool and drain it after you're done to prevent a de facto leak (as the only autorelease pool is in main() at the beginning, so the program will not release until the program quits anyway).
精彩评论