开发者

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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜