2012-03-31 14 views
0

カメラロールから写真を読み込む際にメモリに問題があります。私はストーリーボードとARC(自動参照カウント)を使用しています。私が3番目または4番目の写真をインポートすると、アプリがクラッシュし、実際に楽器が空き物理メモリの下にメモリが残っていないことが示されます。私は@autoreleasepoolsを使用してみましたが、動作していないよう:フォトライブラリからイメージを読み込むときにメモリリークが発生する

- (void)viewDidLoad { 
@autoreleasepool { 
[super viewDidLoad]; 

UIBarButtonItem *cameraButton = [[UIBarButtonItem alloc] 
           initWithTitle:@"Camera" 
           style:UIBarButtonItemStyleBordered 
           target:self 
           action:@selector(useCamera:)]; 

UIBarButtonItem *cameraRollButton = [[UIBarButtonItem alloc] 
            initWithTitle:@"Camera Roll" 
            style:UIBarButtonItemStyleBordered 
            target:self 
            action:@selector(useCameraRoll:)]; 
NSArray *items = [NSArray arrayWithObjects: cameraButton, 
        cameraRollButton, nil]; 
[toolbar setItems:items animated:NO]; 

mouseMoved = 0; 

}} 

- (IBAction) useCamera: (id)sender 
{ 
if ([UIImagePickerController isSourceTypeAvailable: 
    UIImagePickerControllerSourceTypeCamera]) 
{ 
    UIImagePickerController *imagePicker = 
    [[UIImagePickerController alloc] init]; 
    imagePicker.delegate = self; 
    imagePicker.sourceType = 
    UIImagePickerControllerSourceTypeCamera; 
    imagePicker.mediaTypes = [NSArray arrayWithObjects: 
           (NSString *) kUTTypeImage, 
           nil]; 
    imagePicker.allowsEditing = NO; 
    [self presentModalViewController:imagePicker 
          animated:YES]; 

    newMedia = YES; 

    }else{ 
    NSLog(@"Camera is not available"); 
    UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"Important message" message:@"Unfortunately the camera is not available on your device." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil]; 
    [alert1 show]; 
} 

} 

- (IBAction) useCameraRoll: (id)sender 
{ 
@autoreleasepool { 

    if ([self.popoverController isPopoverVisible]) { 
    [self.popoverController dismissPopoverAnimated:YES]; 

    } else{ 

    }{ 
    if ([UIImagePickerController isSourceTypeAvailable: 
     UIImagePickerControllerSourceTypeSavedPhotosAlbum]) 
    { 
     @autoreleasepool { 

     UIImagePickerController *imagePicker = 
     [[UIImagePickerController alloc] init]; 

     imagePicker.delegate = self; 
     imagePicker.sourceType = 
     UIImagePickerControllerSourceTypePhotoLibrary; 
     imagePicker.mediaTypes = [NSArray arrayWithObjects: 
            (NSString *) kUTTypeImage, 
            nil]; 

     imagePicker.allowsEditing = YES; 

     self.popoverController = [[UIPopoverController alloc] 
            initWithContentViewController:imagePicker]; 
     } 
     popoverController.delegate = self; 

     [self.popoverController 
     presentPopoverFromBarButtonItem:sender 
     permittedArrowDirections:UIPopoverArrowDirectionUp 
     animated:YES]; 


     newMedia = NO; 
    }} 
} 
} 

-(void)imagePickerController:(UIImagePickerController *)picker 
didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
    [self.popoverController dismissPopoverAnimated:true]; 
    @autoreleasepool { 


NSString *mediaType = [info 
         objectForKey:UIImagePickerControllerMediaType]; 

    if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) { 
    UIImage *image = [info 
         objectForKey:UIImagePickerControllerOriginalImage]; 

    image1.image = image; 
    if (newMedia) 
     UIImageWriteToSavedPhotosAlbum(image, 
             self, 
              @selector(image:finishedSavingWithError:contextInfo:), 
             nil); 
} 
else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie]) 
{ 
    // Code here to support video if enabled 
}} 
} 

-(void)image:(UIImage *)image 
finishedSavingWithError:(NSError *)error 
contextInfo:(void *)contextInfo 
{ 
if (error) { 
    UIAlertView *alert = [[UIAlertView alloc] 
          initWithTitle: @"Save failed" 
          message: @"Failed to save image"\ 
          delegate: nil 
          cancelButtonTitle:@"OK" 
          otherButtonTitles:nil]; 
    [alert show]; 
} 
} 

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker 
{ 

} 

助けてください!前もって感謝します。

答えて

0

image1.imageはどのように所有権を処理しますか?

使用Heapshot /メモリが失われている方法を見つけるために: 手引きのためにメモリcreapを見つけるためにHeapshotを使用し、以下を参照してください。bbum blog

基本的方法は、直感を実行し、heapshotを取る、楽器は、ツールを割り当てる実行することがありますあなたのコードと別のヒープショットの繰り返し3または4回。これは、反復中に割り当てられ、解放されないメモリを示します。

結果を理解するために、個々の割り当てを参照してください。

あなたが保持し、リリースおよび自動解放オブジェクトの使用機器で発生場所を確認する必要がある場合:楽器で

実行]を、割り当てに(このオプションを設定するには、記録を停止しなければならない上に「レコードの参照カウント」を設定)。ピッカーを実行し、録画を停止し、ivar(datePickerView)を検索し、ドリルダウンして、すべての保持、リリース、および自動リースが発生した場所を確認することができます。

0

は同じ問題を持っています。 作成した新しいアイテムごとに2〜3 MBを使用します。 責任の発信者= CGDataProviderCreateWithCopyOfData

は、画像を編集する使用している場合、これが適切に解放されないようです

imagePicker.allowsEditing = NO; 

を設定する必要がありました。

関連する問題