2012-04-06 7 views
0

アイフォーンでこのプログラムを実行すると、4つの画像メモリに警告が発生し、アプリがクラッシュすることがあります。だから私を助けてくださいありがとう私はちょうど画像の参照を取得し、ファイルに書き込んで、ファイルパスから画像を取得します。ありがとうUIImagePickerViewControllerフォトライブラリから画像を取得中にiphoneでメモリ警告が発生する

- (IBAction)addPicsButtonClick:(id)sender 
{ 
    UIImagePickerController * picker = [[[UIImagePickerController alloc] init] autorelease]; 
    picker.delegate = self; 
    picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;  
    [self presentModalViewController:picker animated:YES];  
} 


- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker 
{ 
    [picker dismissModalViewControllerAnimated:YES]; 
} 

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{   
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *pathToDocuments=[paths objectAtIndex:0]; 
    AppDelegate *app = [[UIApplication sharedApplication] delegate]; 
    NSData *imageData = UIImageJPEGRepresentation([info objectForKey:@"UIImagePickerControllerOriginalImage"], 0.3f);  
    [imageData writeToFile:[NSString stringWithFormat:@"%@/%d.jpg", pathToDocuments, [app.images count]] atomically:YES];  
    [self dismissModalViewControllerAnimated:YES]; 

} 
+0

あなたの問題を解決できるかもしれないautoreleaseプールのaddPicsButtonClickのあなたのコードを保つ。 – Leena

答えて

0

私はシミュレータの新しいアプリケーションで同じコードを実行し、クラッシュの問題やメモリ警告がなく、ファイルを作成しました。 app.imagesはこのコードのどこにも設定されていないので、私は[app.images count]を取り出して代わりにローカル変数を使用しました。したがって、その変数がごみ箱になっていたり、過剰にリリースされていたりすると、それが問題になる可能性があります。

関連する問題