AVAssetWriterInputPixelBufferAdaptor内存管理

Igo*_*iuc 6 memory-management avfoundation core-video ios avassetwriter

我正在使用AVAssetWriterInputPixelBufferAdaptor为视频编写一些帧,当我写了很多帧时,我的应用程序因内存分配而崩溃.我怎么能防止这种情况?这是代码:

AVAssetWriterInput *writerInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoSettings];  

NSDictionary *sourcePixelBufferAttributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
                                                       [NSNumber numberWithInt:kCVPixelFormatType_32ARGB], kCVPixelBufferPixelFormatTypeKey, nil];

 AVAssetWriterInputPixelBufferAdaptor *adaptor = [AVAssetWriterInputPixelBufferAdaptor           
 assetWriterInputPixelBufferAdaptorWithAssetWriterInput:writerInput  
 sourcePixelBufferAttributes:sourcePixelBufferAttributesDictionary]; 


CVPixelBufferRef buffer = NULL;
                buffer = (CVPixelBufferRef)[self pixelBufferFromCGImage:[tmpImg CGImage] size:size];
                if (buffer)
                {
                    if(![adaptor appendPixelBuffer:buffer withPresentationTime:presentTime])
                        NSLog(@"FAIL");
                    else
                        NSLog(@"Success:%d",i);
                        CFRelease(buffer);

                }
Run Code Online (Sandbox Code Playgroud)

当使用Xcode Instruments时,泄漏似乎发生在

if(![adaptor appendPixelBuffer:buffer withPresentationTime:presentTime])
Run Code Online (Sandbox Code Playgroud)

(AVAssetWriterInputPixelBufferAdaptor)

真的可以使用一些帮助或指向一个工作示例的指针.谢谢!