So I had a problem converting some audio. When converting, I get a huge memory leak, and it comes from these lines of code.
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 {
The line that appears to be causing the leak: CMSampleBufferRef nextBuffer = [assetReaderOutput copyNextSampleBuffer];
I got lost on this, any help would be greatly appreciated.
ANSWER: Fixed. Just add these lines at the end of the if / else statement.
CMSampleBufferInvalidate(nextBuffer); CFRelease(nextBuffer); nextBuffer = nil;
Krzemienski
source share