gpt4 book ai didi

iphone - 从 substringWithRange 泄漏内存

转载 作者:行者123 更新时间:2023-11-28 17:43:24 26 4
gpt4 key购买 nike

仪器通知我我正在从以下代码片段中泄漏内存

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 类是一个非常简单的容器类,其中的每个变量都在类的 dealloc 中释放。

这可能是什么问题?

我在循环开始时分配 aLTR,然后在循环结束时释放 aLTR。NSString 方法都是在返回的字符串上自动释放 AFAIK,因此代码看起来很紧凑。

有人能阐明这种令人困惑的情况吗?构建和分析工具在这里也没有提到任何问题。

非常感谢,-代码

最佳答案

[self.theLeagueTableArray addObject:aLTR];

如果此 theLeagueTableArray 的支持实例变量从未被释放,那么其中的任何联赛表行也不会被释放。检查此类的 dealloc 方法并确保变量已在那里释放。

关于iphone - 从 substringWithRange 泄漏内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7191561/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com