私はiPhoneアプリを作成中ですが、メモリにいくつか問題があります。以下のコードは次のとおりです。
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);
ユーザーのiTunesライブラリから曲を読んでいます(curItemは現在の曲です)。最後の行を残すとCFRelease(sample)
、コードでプログラムが停止します(エラーは表示されません)。クラッシュするだけです。この行をコメントアウトすると、もちろんメモリの問題が発生し、「Receivedmemorywarning」を受け取った後の4曲目あたりでコードがクラッシュします。
私は何が間違っているのですか?