Iphone 正在从substringWithRange泄漏内存
Instruments通知我正在从以下代码段泄漏内存Iphone 正在从substringWithRange泄漏内存,iphone,objective-c,ios,Iphone,Objective C,Ios,Instruments通知我正在从以下代码段泄漏内存 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) { } i
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];
}
for(int x=0;x([substring length]))
{
}
substring=[substring substringfromfromindex:(match.location+match.length)];
match2=[子字符串rangeOfString:@“title=”;
substring=[substring substringfromfromindex:(match2.location+match2.length+1)];
match2=[子字符串rangeOfString:@“>”];
aLTR.teamName=[substring substringToIndex:match2.location-1]//这里漏一个百分比
match2=[子字符串rangeOfString:@“number total mp”];
substring=[substring substringfromfromindex:(match2.location+match2.length+1)];
匹配=[子字符串rangeOfString:@“>”;
match2=[substring rangeOfString:@“仪器无法显示泄漏实际发生的位置,只能显示泄漏内存的分配位置
在您的案例中,第二次泄漏(对属性的分配完成)很可能只是原始泄漏的结果
最初的泄漏是您第一次评论时标记的LeagueTableRow
实例
这个特定的代码看起来还可以,我会去检查theLeagueTableArray
属性如何处理它的内存。它是在应该的时候释放内存的吗?实现它的类是不是应该释放这个属性的后备存储区?根据我的经验,泄漏的原因通常不是alloc调用。Wh至少你会发现你把这个联赛桌上的球传给了别的东西,而你却忘了释放它
在保留LeagueTableRow实例的任何地方查看您的代码,它不会在某个地方发布
[self.theLeagueTableArray addObject:aLTR];
如果此LeagueTableArray
的backing instnce变量从未释放,则其中的任何联赛表行也不会释放。请检查该类的dealloc方法,并确保该变量已在那里释放