substringToString 产生泄漏

发布于 2024-10-29 00:32:59 字数 851 浏览 5 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初见你 2024-11-05 00:32:59

这些 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文