首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将拾取的图像摄像机从一个视图传输到另一个视图时出现内存警告

将拾取的图像摄像机从一个视图传输到另一个视图时出现内存警告
EN

Stack Overflow用户
提问于 2013-05-03 15:45:26
回答 1查看 141关注 0票数 0

我在按钮上打开相机,点击并拍摄uiimage中的图像,然后将uiimage传输到其他视图,但当我这样做4-5次时,我收到内存警告。

以下是我工作过的代码:

代码语言:javascript
复制
-(void)imagePickerController:(UIImagePickerController*)picker_camera didFinishPickingMediaWithInfo:(NSDictionary*)info
{
    [picker_camera dismissModalViewControllerAnimated:YES];
    UIImage *image=[[UIImage alloc] init];
    image=[info objectForKey:@"UIImagePickerControllerOriginalImage"];

    [self Methodcall:image];
    //Image_camera=image;
   // NSAutoreleasePool *apool = [[NSAutoreleasePool alloc] init];
    //printf("first\n");

   // [self performSelector:@selector(Methodcall) withObject:nil afterDelay:1];

    //printf("ok\n");
    //[apool release];

}
-(void)Methodcall:(UIImage *)image{
    ImageDisplayViewController *ImageDisplayViewController_obj=[[ImageDisplayViewController alloc] initWithNibName:@"ImageDisplayViewController" bundle:nil];
    ImageDisplayViewController_obj.image_FRomCamera=image;
    NSLog(@"image===>%@    camera==>%@",image,ImageDisplayViewController_obj.image_FRomCamera);
    [self.navigationController pushViewController:ImageDisplayViewController_obj animated:YES];
   // [ImageDisplayViewController_obj release];
}

-(IBAction)TakePhotoCamera:(id)sender{
    @try
    {
        UIImagePickerController *picker_camera = [[UIImagePickerController alloc] init];
        picker_camera.sourceType = UIImagePickerControllerSourceTypeCamera;
        picker_camera.delegate = self;

        [self presentModalViewController:picker_camera animated:YES];
        [picker_camera release];
    }
    @catch (NSException *exception)
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Camera" message:@"Camera is not available  " delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
}

有谁能帮帮我吗?

提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2013-05-03 16:09:08

我假设你没有使用ARC (有什么特别的原因吗?)

  • 首先,您正在分配一个从未使用过的UIImage实例:

objectForKey:@"UIImagePickerControllerOriginalImage";UIImage *image=[UIImage alloc init];image=info alloc init

应更改为:

UIImage *image = info objectForKey:@"UIImagePickerControllerOriginalImage";

  • Next,此处未释放ImageDisplayViewController_obj实例:

// ImageDisplayViewController_obj发布;

取消此行的注释。

内存管理的黄金法则:总是释放你不再需要的对象,并且不保留任何你不需要的东西。

如果你是Obj-C和/或内存管理的新手,我强烈推荐使用ARC。

其他一些建议:

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16353949

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档