【发布时间】:2011-08-25 13:52:00
【问题描述】:
仪器通知我,我正在从以下代码 sn-p 泄漏内存
for (int x=0; x<20; x++)
{
LeagueTableRow *aLTR = [[LeagueTableRow alloc] init]; //leaks a certain percentage here
match = [substring rangeOfString: @"text team large-link"];
if (match.location == NSNotFound)
{
}
if ((match.location + match.length) > ([substring length]))
{
}
substring = [substring substringFromIndex:(match.location + match.length)];
match2 = [substring rangeOfString: @"title="];
substring = [substring substringFromIndex:(match2.location + match2.length+1)];
match2 = [substring rangeOfString: @">"];
aLTR.teamName = [substring substringToIndex:match2.location-1]; //leaks a percentage here
match2 = [substring rangeOfString: @"number total mp"];
substring = [substring substringFromIndex:(match2.location + match2.length+1)];
match = [substring rangeOfString: @">"];
match2 = [substring rangeOfString: @"<"];
aLTR.played = [substring substringWithRange:NSMakeRange(match.location+1, (match2.location-(match.location+1)))]; //leaks a percentage here
[self.theLeagueTableArray addObject:aLTR];
[aLTR release];
}
仪器通知我泄漏,并且我在代码中评论说有泄漏,它说这条线是一定比例的泄漏的原因。
LeagueTableRow 类是一个非常简单的容器类,其中的每个 var 都会在该类的 dealloc 处释放。
这可能是什么问题?
我在循环开始时分配 aLTR,然后在循环结束时释放 aLTR。 NSString 方法都是自动释放返回的字符串 AFAIK 所以代码看起来很紧凑。
任何人都能够阐明这个令人困惑的情况?构建和分析工具在这里也没有提到任何问题。
非常感谢, -代码
【问题讨论】:
标签: iphone objective-c ios