So I am having a problem with converting some audio. I am getting a huge memory leak when converting 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
{
// 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;
}
}
}];
The line that seems to cause the leaks is: CMSampleBufferRef nextBuffer = [assetReaderOutput copyNextSampleBuffer];
I'm lost on this one 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; // NULL?
ANSWER: Fixed - Just add these lines at the end of the if/else statement.
CMSampleBufferInvalidate(nextBuffer);
CFRelease(nextBuffer);
nextBuffer = NULL;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With