iPhone代码泄漏,我不知道为什么

Ste*_*fan 1 iphone cocoa-touch memory-leaks memory-management

这是一个众所周知的片段,如何从iPhone照片库中选择一张图片:

- (IBAction)selectExistingPicture {
  if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    [self presentModalViewController:picker animated:YES];
            [picker release];

  }
}
Run Code Online (Sandbox Code Playgroud)

在这里,您可以看到仪器的屏幕截图(全屏).

替代文字http://img.skitch.com/20090624-rtqp2mgsnyynkgb97c9e8d2g9c.jpg

它为什么泄漏?我不明白,因为选择器被正确释放,我想.

rpe*_*ich 6

UIImagePickerController公知的泄漏.如果您打算多次使用它,建议您重复使用单个实例

  • 好的谢谢.奇怪的是,Apple因泄漏而拒绝了应用程序,但本身也会产生泄漏. (2认同)