iphone - 从 substringWithRange 泄漏内存

标签 iphone objective-c ios

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

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/

相关文章:

objective-c - 重复使用细胞... :(

ios - WhirlyGlobe-Maply 杆

android - Firebase 分析 - 如何在事件详细信息 View 中查看所有用户属性

iphone - 自定义按钮的核心图形与图像

iphone - 将按钮添加到 UITableViewCell

ios - 模糊效果未正确调整到父 View

iphone - 将对象插入到索引 1 处的 NSMutableArray 时出现奇怪的结果

iphone - 学习 objective-c 更有助于理解计算机体系结构

ios - 为 iOS map View 提供自定义颜色

iphone - 直接编写使用 Foundation 类型的 C 代码吗?