gpt4 book ai didi

iphone - CMSampleBufferRef 内存泄漏

转载 作者:可可西里 更新时间:2023-11-01 03:28:35 25 4
gpt4 key购买 nike

所以我在转换一些音频时遇到了问题。我在转换时遇到了巨大的内存泄漏,它来自这些代码行。

dispatch_queue_t mediaInputQueue = dispatch_queue_create("mediaInputQueue", NULL);
[assetWriterInput requestMediaDataWhenReadyOnQueue:mediaInputQueue
usingBlock: ^
{

while (assetWriterInput.readyForMoreMediaData)
{
CMSampleBufferRef nextBuffer = [assetReaderOutput copyNextSampleBuffer];
if (nextBuffer)
{

[assetWriterInput appendSampleBuffer: nextBuffer];
nextBuffer = NULL;

}
else
{
// done!
[assetWriterInput markAsFinished];
[assetWriter finishWriting];
[assetReader cancelReading];
NSDictionary *outputFileAttributes = [[NSFileManager defaultManager]
attributesOfItemAtPath:exportPath
error:nil];





NSNumber *doneFileSize = [NSNumber numberWithLong:[outputFileAttributes fileSize]];
[self performSelectorOnMainThread:@selector(updateCompletedSizeLabel:)
withObject:doneFileSize
waitUntilDone:NO];

// release a lot of stuff
[assetReader release];
[assetReaderOutput release];
[assetWriter release];
[assetWriterInput release];
[exportPath release];
break;
}
}

}];

似乎导致泄漏的行是: CMSampleBufferRef nextBuffer = [assetReaderOutput copyNextSampleBuffer];

我迷失在这个问题上,我们将不胜感激。

回答:固定 - 只需在 if/else 语句的末尾添加这些行。

CMSampleBufferInvalidate(nextBuffer);
CFRelease(nextBuffer);
nextBuffer = nil; // NULL?

最佳答案

答案:已修复 - 只需在 if/else 语句的末尾添加这些行。

CMSampleBufferInvalidate(nextBuffer);
CFRelease(nextBuffer);
nextBuffer = NULL;

关于iphone - CMSampleBufferRef 内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9355175/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com