我正在編寫一個iPhone應用程序,並且有一些內存問題。這是下面的代碼:程序崩潰在Xcode中沒有顯示錯誤
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)
代碼,該程序將停止 - 沒有錯誤顯示 - 它只是崩潰。如果我註釋掉了這一行,我當然會遇到內存問題,並且在得到「收到內存警告」後,代碼會在第四首歌曲中崩潰。
我在做什麼錯?