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