【问题标题】:Received memory warning. with ipad camera收到内存警告。带 ipad 相机
【发布时间】:2013-08-21 08:10:50
【问题描述】:

当我在我的应用程序中打开相机时,它工作正常,但是当我在我的应用程序中导航并返回相机视图并再次尝试在 iPad 中打开我的相机时,应用程序崩溃并给我“收到内存警告”。应用程序在 iPhone 上运行良好,而这个问题只出现在 iPad 上。

我的项目没有 ARC,所以我将我的项目转换为 ARC 以希望获得良好的结果,但我的应用程序在很少导航后仍然在相机上崩溃。 谁能告诉我如何使用 iPad 相机减少内存空间,以便我的应用程序停止收到内存警告。

这是我的相机代码

if ([UIImagePickerController isSourceTypeAvailable:
         UIImagePickerControllerSourceTypeCamera])
    {
        imagePicker=[[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.sourceType =UIImagePickerControllerSourceTypeCamera;
        imagePicker.allowsEditing = NO;
        //imagePicker.modalPresentationStyle = UIModalPresentationFullScreen;

        [self presentViewController:imagePicker animated:YES completion:nil];
   } 

这是我获取图像的地方

-(void)imagePickerController:(UIImagePickerController *)picker     didFinishPickingMediaWithInfo:(NSDictionary *)info
{
        [Array removeAllObjects];

        [picker dismissViewControllerAnimated:YES completion:nil];
        image = [info objectForKey:UIImagePickerControllerOriginalImage];

        [array addObject:image];
        image=nil;

}

我也尝试使用 popOverview 进行摄像头,但也没有用。

在我调用 UIImagePickerController 的 viewController 中,我使用了 5 个动画,在我在 viewWillAppear 中调用动画之前,应用程序崩溃了,所以我将动画调用更改为 ViewDidLoad 并且相机开始工作,但直到我导航到我的最后一个视图并再次打开相机。

【问题讨论】:

  • 问题不在于相机。您可能没有正确丢弃使用过的和不必要的对象。
  • 您是在使用 iOS 默认的相机选择器还是将相机连接到预览层或例如您是使用 OpenGL 还是 CoreImage 处理每个视频缓冲区?
  • @Desdenova 我现在正在使用 ARC,我该如何释放对象。
  • @Markus 不,兄弟我正在打开相机而不是使用 openGL

标签: iphone ios objective-c xcode ipad


【解决方案1】:

我遇到了同样的问题,所以我喜欢这个。

像这样将 UIImagePickerController 设置为静态。

 static UIImagePickerController *imagePicker;

当您在此删除中获得图像时。

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 
  @autoreleasepool {// to release memory

   // Probelm is you image size. 
   // When you get this image it is vary large.
   // And i hope  you are creating multiple copy's of this image.

   // when you get image in 
   UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

    // In last set image as nil
   image = nil;
  }
}

希望这能解决你的问题.. :-)

【讨论】:

  • xcode 在静态“类型名称不允许指定存储类”上显示错误
  • 关注stackoverflow.com/questions/14960249/… --> 在女巫电话中,您在 .h 或 .m 中声明静态变量均值。如果它在 .h 中,则从中删除并在 .m 文件中重新声明
【解决方案2】:

尝试在没有动画的情况下运行您的应用,然后尝试,如果它有效,那么您需要改进动画内存分配,因为动画需要大量内存。

【讨论】:

    【解决方案3】:

    请尝试下面的代码。在弹出窗口中尝试UIImagePickerController

    if([UIImagePickerContrller isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {
            UIImagePickerController *controller = [[UIImagePickerController alloc] init];
            controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            controller.allowsEditing = YES;
            controller.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
            controller.delegate = self;
            UIPopoverController *popController = [[UIPopoverController alloc]  initWithContentViewController:controller];
            popController.popoverContentSize = CGSizeMake(350.0f, 500);
            [popController presentPopoverFromRect: self.button.frame inView:self.button.superview
                         permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES]
    }
    

    【讨论】:

    • 我已经在我的问题中提到 popover 没有解决我的问题。第二在你的代码中你给 UIImagePickerControllerSourceTypePhotoLibrary 作为源类型?
    猜你喜欢
    • 2012-07-05
    • 1970-01-01
    • 1970-01-01
    • 2011-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多