Objective C subStringToIndex 内存泄漏

发布于 2024-12-11 04:15:02 字数 882 浏览 0 评论 0原文

我使用 xcode 4.2 for 10.6 和 ios 5,当我使用 xcode 分析项目时,报告了这个奇怪的内存泄漏。

代码如下:

- (void) imagePickerController: (UIImagePickerController*) reader
didFinishPickingMediaWithInfo: (NSDictionary*) info
{
id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for (symbol in results) break;
[reader dismissModalViewControllerAnimated: NO];

[self beep];
NSString *upcScanned = [NSString stringWithFormat:@"0%@", symbol.data]; //line 1
NSString * name = [self getItemName:upcScanned];
ProductNameDialog *dialog = [[ProductNameDialog alloc] initWithNibName:@"ProductNameDialog" bundle:nil];

//dialog.upcScanned = [upcScanned substringToIndex:[upcScanned length] - 1];//line 2
[name release];
[self presentModalViewController:dialog animated:YES];
[dialog release];        
}

line2 是报告内存泄漏的行。

I use xcode 4.2 for 10.6, and ios 5, and have this strange memory leak reported when I profile the project using xcode.

Here is the code:

- (void) imagePickerController: (UIImagePickerController*) reader
didFinishPickingMediaWithInfo: (NSDictionary*) info
{
id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for (symbol in results) break;
[reader dismissModalViewControllerAnimated: NO];

[self beep];
NSString *upcScanned = [NSString stringWithFormat:@"0%@", symbol.data]; //line 1
NSString * name = [self getItemName:upcScanned];
ProductNameDialog *dialog = [[ProductNameDialog alloc] initWithNibName:@"ProductNameDialog" bundle:nil];

//dialog.upcScanned = [upcScanned substringToIndex:[upcScanned length] - 1];//line 2
[name release];
[self presentModalViewController:dialog animated:YES];
[dialog release];        
}

line2 was the line reported memory leak.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

梦途 2024-12-18 04:15:02

最合乎逻辑、最可能的结论是方法 [self getItemName:upcScanned] 保留传入的字符串但不释放它。

The most logical, and most probable conclusion is the the method [self getItemName:upcScanned] retains the passed in string but does not release it.

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