I am in the process of writing an iPhone app, and am having a few problems with the memory. Here is the code below:
NSURL *url = [curItem valueForProperty: MPMediaItemPropertyAssetURL];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL: url options:nil];
NSError *error = nil;
AVAssetReader* reader = [[AVAssetReader alloc] initWithAsset:asset error:&error];
AVAssetTrack* track = [[asset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0];
NSMutableDictionary* audioReadSettings = [NSMutableDictionary dictionary];
[audioReadSettings setValue:[NSNumber numberWithInt:kAudioFormatLinearPCM]
forKey:AVFormatIDKey];
AVAssetReaderTrackOutput* readerOutput = [AVAssetReaderTrackOutput assetReaderTrackOutputWithTrack:track outputSettings:audioReadSettings];
[reader addOutput:readerOutput];
[reader startReading];
CMSampleBufferRef sample = [readerOutput copyNextSampleBuffer];
while( sample != NULL)
{
sample = [readerOutput copyNextSampleBuffer];
}
CFRelease(sample);
I am reading songs from the user's iTunes library (curItem is the current song), and if I leave the last line: CFRelease(sample)
in the code, the program will stop - no error is shown - it just crashes. If I comment out the line, I of course run into memory problems, and the code crashes on about the fourth song after getting "Received memory warning."
What am I doing wrong?