Objective C subStringToIndex 内存泄漏
我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最合乎逻辑、最可能的结论是方法
[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.