0

我已经使用仪器测试了我的应用程序,它显示了以下泄漏。 在此处输入图像描述

当我双击堆栈跟踪中的 CameraVC 时,它会在我的代码中引用以下行。 在此处输入图像描述

当我调用相机时会发生这种情况,我使用以下代码调用它:-

      - (IBAction) getCamera
{
    // set up our camera overlay view   
    // tool bar - handy if you want to be able to exit from the image picker...
    UIToolbar *toolBar=[[UIToolbar alloc] initWithFrame:CGRectMake(0, 480-44, 320, 44)];

    UIBarButtonItem *spaceItem  = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace  target:nil action:nil] autorelease];
    UIBarButtonItem *spaceItem1  = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace  target:nil action:nil] autorelease];
    UIBarButtonItem *cancelItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel  target:self action:@selector(cancelPickingImag)] autorelease];
    UIBarButtonItem *cameraItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera  target:self action:@selector(finishedAugmentedReality)] autorelease]; 

    spaceItem.width  = 2.0;
    spaceItem1.width = 55.0;
    NSArray *items=[NSArray arrayWithObjects:spaceItem,cancelItem,spaceItem1,cameraItem,nil];
    [toolBar setItems:items];

    // create the overlay view
    overlayView=[[OverlayView alloc] initWithFrame:CGRectMake(0, 300, 320, 480-44)];

    // important - it needs to be transparent so the camera preview shows through!
    overlayView.opaque=NO;
    overlayView.backgroundColor=[UIColor clearColor];

    // parent view for our overlay
    UIView *parentView=[[UIView alloc] initWithFrame:CGRectMake(0,0,320, 480)];
    [parentView addSubview:overlayView];
    [parentView addSubview:toolBar];
    [parentView addSubview:lbl];
    [parentView addSubview:overlayGraphicView];

    // configure the image picker with our overlay view
    //UIImagePickerController *picker=[[UIImagePickerController alloc] init];

    if ([UIImagePickerController isSourceTypeAvailable:
         UIImagePickerControllerSourceTypeCamera])
    {
        imagePicker = [[UIImagePickerController alloc] init];
        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;

        // hide the camera controls
        imagePicker.showsCameraControls=NO;

        imagePicker.delegate = self;
        //imagePicker.allowsImageEditing = NO;

        // and put our overlay view in
        imagePicker.cameraOverlayView=parentView;
    }
    else
    {
        imagePicker = [[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        imagePicker.mediaTypes = [NSArray arrayWithObjects:
                                  (NSString *) kUTTypeImage,
                                  nil];
        imagePicker.allowsEditing = NO;

    }

    [self presentModalViewController:imagePicker animated:YES];

    //Free memory 
    [imagePicker release];//,imagePicker =nil;
    [parentView release], parentView=nil;
    [overlayGraphicView release], overlayGraphicView= nil;
    [lbl release], lbl=nil;
    [overlayView release];//, overlayView =nil;
    [toolBar release], toolBar=nil;
}

非常感谢任何帮助

谢谢

4

1 回答 1

0

parentView正在被创建[alloc [init...]],意味着它是retained。然后将它分配给 的cameraOverlayView属性imagePicker,这意味着它会retain再次被编辑。完成该任务后,您需要release它。

(这几乎可以肯定是“泄漏”的原因,但不会导致“崩溃”。你说你遇到了崩溃,但根本没有描述。)

于 2012-07-12T15:52:04.167 回答