objective c subStringToIndex内存泄漏

时间:2011-10-22 22:37:30

标签: objective-c memory-leaks

我使用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是报告内存泄漏的行。

1 个答案:

答案 0 :(得分:0)

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