1

で 25MB のメモリバーストを観察しています[self setImageData:[AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer]];

以下のコード スニペットは、画像をキャプチャし、jpg 形式のデータを提供しています。さらに写真を撮ると、システムはメモリ不足の警告を報告しています。

プロファイラーではリークは見られませんが、アプリケーションが 20MB でもメモリ不足の警告を報告し、アプリケーションがクラッシュすることがあります。

[[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:videoConnection 
                                        completionHandler:^(CMSampleBufferRef imageSampleBuffer, NSError *error) 
 {
     [[self captureSession] stopRunning];
     if (imageSampleBuffer != NULL) 
     {
         CFDictionaryRef exifAttachments = CMGetAttachment(imageSampleBuffer, kCGImagePropertyExifDictionary, NULL);
         if (exifAttachments) 
         {
             NSLog(@"attachements: %@", exifAttachments);
         }


         [self setImageData:[AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer]];
     }
     imageSampleBuffer = nil;

     // call the designated delegate 
     [self.aCDMCameraCaptureNotificationDelegate imageDidSuccessfullyCaptured];
 }];
4

2 に答える 2

0

プロファイリング後、次のメモリ リークが見られます。

#   Address Category    Event Type  RefCt   Timestamp   Size    Responsible Library Responsible Caller
0   0x2087cb80  __NSDate    Malloc  1   00:18.446.047   16  AVFoundation    -[AVCaptureSession _stopPreviewing]
1   0x2087cb80  __NSDate    Autorelease     00:18.446.056   0   AVFoundation    -[AVCaptureSession _stopPreviewing]
2   0x2087cb80  __NSDate    Release 0   00:28.472.781   0   Foundation  -[NSAutoreleasePool drain]
3   0x2087cb80  __NSDate    Free    0   00:28.472.787   -16 Foundation  -[NSAutoreleasePool drain]
4   0x2087cb80  Malloc 16 Bytes Malloc  1   00:42.834.501   16  libdispatch.dylib   _dispatch_call_block_and_release

このメモリ リークの原因となっているステートメントを指摘できますか?

于 2013-08-21T06:06:15.343 に答える
0

画像は、解像度によっては、メモリ内のスペースを少し占有する場合があります。作成している画像がすべてを占有しないようにする必要があります。SDWebImage と呼ばれる Web イメージ キャッシュ ライブラリがあり、イメージをメモリ内およびディスク上のキー バリュー ストアに格納できるため、メモリの負荷が大きくなりすぎた場合はメモリ内のイメージ キャッシュをフラッシュし、イメージを復元する必要がある場合は呼び出すことができます。ディスクから。

画面に画像を表示している場合は、キャプチャからの 1 つの画像で問題ありませんが、複数の画像を表示している場合は、画像のサイズを対応する imageView サイズに縮小し、元の両方をキャッシュに保存することを検討してください。

于 2013-08-20T12:38:12.470 に答える