substringToString 产生泄漏
我在 tempstr = [tempstr substringToIndex... 行发生内存泄漏 我已经尝试了分配 tempStr 的所有可能组合, NSString *tempStr = @""; NSString *tempStr = [[NSString alloc] init]; (在循环结束时释放) 我尝试过调整 NSString 的范围。没有什么。产生 3 次泄漏 任何有关我可以尝试修复它的帮助将不胜感激。
while(x < [arr1 count]){
//NSLog(@"%@", [arr1 objectAtIndex:x]);
if([[arr1 objectAtIndex:x] rangeOfString:@".com"].location != NSNotFound)
{
//NSLog(@"%@", [arr1 objectAtIndex:x]);
tempStr = [[arr1 objectAtIndex:x] substringFromIndex:[[arr1 objectAtIndex:x] rangeOfString:@"http://"].location];
tempStr = [tempStr substringToIndex:tempStr.length - 1];
[arr1 replaceObjectAtIndex:x withObject:tempStr];
//NSLog(@"%@", [arr1 objectAtIndex:x]);
}
..... more code....
x++
}
Ive been getting a memory leak at the line tempstr = [tempstr substringToIndex...
Ive tried every possible combination of allocation tempStr,
NSString *tempStr = @"";
NSString *tempStr = [[NSString alloc] init]; (with a release at the end of the loop)
ive tried adjusting the scope of the NSString. NOTHING. Its producing 3 leaks
Any help on what i can try to fix it would be much appreciated.
while(x < [arr1 count]){
//NSLog(@"%@", [arr1 objectAtIndex:x]);
if([[arr1 objectAtIndex:x] rangeOfString:@".com"].location != NSNotFound)
{
//NSLog(@"%@", [arr1 objectAtIndex:x]);
tempStr = [[arr1 objectAtIndex:x] substringFromIndex:[[arr1 objectAtIndex:x] rangeOfString:@"http://"].location];
tempStr = [tempStr substringToIndex:tempStr.length - 1];
[arr1 replaceObjectAtIndex:x withObject:tempStr];
//NSLog(@"%@", [arr1 objectAtIndex:x]);
}
..... more code....
x++
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些
tempStr
实例应该进入自动释放池,因此,如果您正确使用自动释放池,它们应该在适当的时候正确释放。因此,您要么很早就测量泄漏(直到循环完成后很长时间才会释放对象),要么您正在处理自动释放池尚未正确设置的线程。
Those
tempStr
instances should be going to the autorelease pool, thus if you are using the autorelease pool properly, they should be released properly, in due time.Thus, you are either measuring the leak very early (the objects won't be released until long after the loop is finished), or you are working on a thread where the autorelease pool has not been setup properly.