1
我用从苹果公司的“摄像头编程主题为iOS指南一些代码如下:内存泄漏
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
// Displays a control that allows the user to only take picture:
cameraUI.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeImage, nil];
// Hides the controls for moving & scaling pictures, or for trimming movies. To instead show the controls, use YES.
cameraUI.allowsEditing = NO;
cameraUI.delegate = delegate;
[controller presentModalViewController: cameraUI animated: YES];
[cameraUI release];
然而,当我“分析”我的代码,Xcode中说,我有一个潜在的从以下行泄漏:
cameraUI.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeImage, nil];
我没有其他release
命令比上面显示的那些。鉴于问题的阵列是CameraUI的(被释放)的属性,林不知道我应该做的(如果有的话)。
有什么想法?
啊理解。是的,这是工作。快速问题,但...为什么第二种形式更容易出错(我的应用程序中我有类似的代码)。 – 2012-04-15 13:54:01
第二种形式,当你写它工作正常,但随着程序的增长很容易把代码行分配与释放之间。然后在某个时候你不小心删除了这个版本,或者把它移到一个if语句中。第一个版本更容易意外中断。在另一方面,把一切在自动释放池可能意味着你耗尽内存池被耗尽之前... – Dondragmer 2012-04-15 14:00:52
稀释是 - ,所有有意义了。所以它容易出现人为错误!谢谢 – 2012-04-15 14:01:42