从字符串的部分创建数组时内存泄漏

时间:2011-07-08 10:32:37

标签: iphone objective-c ios

timeListArray是我在课堂上的全局变量 这是我的代码: -

NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *return_string5 = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSArray *dairyTimeParts = [return_string5 componentsSeparatedByString:@"\""];
[timeListArray removeAllObjects];

for(int i=1;i<[dairyTimeParts count]/2;i=i+2)
{
    [timeListArray addObject:[dairyTimeParts objectAtIndex:2*i+1]];
}

1 个答案:

答案 0 :(得分:1)

问题在于这一行:

NSString *return_string5 = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];

简而言之,当你完成任务时alloc你自己必须release。尝试在[return_string5 release];循环后添加for