【发布时间】:2013-08-26 12:41:59
【问题描述】:
我正在使用代码从相机捕捉帧:
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
:(AVCaptureConnection *)connection
{
// Create a UIImage from the sample buffer data
UIImage *image = [self imageFromSampleBuffer:sampleBuffer];
if(delegate && [delegate respondsToSelector:@selector(captureManagerCapturedFrame:withFrameImage:withFrameBuffer:)]) {
[delegate captureManagerCapturedFrame:self withFrameImage:image withFrameBuffer:sampleBuffer];
}
}
我这样做是因为在委托方法captureManagerCapturedFrame:withFrameImage:withFrameBuffer: 中我有一个标志告诉应用程序使用返回的uiimage 或返回的sampleBuffer。
委托方法是:
- (void) captureManagerCapturedFrame:(AVCamCaptureManager *)captureManager
withFrameImage:(UIImage *)image
withFrameBuffer:(CMSampleBufferRef)frameBuffer {
if(_screen1) {
NSLog(@"Only display camera image\n");
}
else if(_screen2) {
//Enable IR
NSLog(@"Display AND Process camera image\n");
[self imageReconigitionProcessFrame:frameBuffer];
}
}
imageReconigitionProcessFrame: 在哪里:
-(void)imageReconigitionProcessFrame:(CMSampleBufferRef)frameBuffer {
//CFRetain(frameBuffer);
MSImage *qry = [[MSImage alloc] initWithBuffer:frameBuffer orientation:AVCaptureVideoOrientationPortrait]; //MEMORY LEAK HERE???
qry = nil;
//CFRelease(frameBuffer);
}
此代码有效。 但这是我的问题。当此代码在仪器中运行和分析时,我看到使用的 overall bytes 快速增加,但分配分析器似乎没有增加。使用泄漏工具也看不到任何“泄漏”。但很明显,每次调用imageReconigitionProcessFrame: 都会快速增加内存,并且应用程序会在几秒钟后崩溃。当我将frameBuffer 设置为nil 时,内存不会增加(或者当然我也没有帧缓冲区来进行任何处理)。
我曾尝试使用CFRetain 和CFRelease(在上面的代码中注释掉)转移frameBuffer 的所有权,但这些似乎也没有任何作用。
有谁知道我可能在这个函数中泄漏内存的地方???
[[MSImage alloc] initWithBuffer: 方法是第三方 SDK(Moodstocks,这是一个很棒的图像识别 SDK),它在他们的演示中运行良好,所以我认为问题不在于这个函数。
【问题讨论】:
标签: iphone ios objective-c core-foundation