1
我創建了AVAudioUnitSampler
,但在通過Instruments
工具檢查內存後,看起來在場景改變時,即使AVAudioUnitSampler
對象爲零,它第一次初始加載的資源仍然是在記憶中。當我重新創建採樣器時,它會重新加載資源,現在我已經爲採樣器增加了兩倍的內存。我如何強制資源釋放?AVAudioUnitSampler未釋放資源
下面的代碼:
-(void) loadSampler {
// Instatiate audio engine
_engine = [[AVAudioEngine alloc] init];
_mixer = [_engine mainMixerNode];
_sampler = [[AVAudioUnitSampler alloc] init];
[self loadSoundFontInstrument]; //sound font is the instrument that the sampler will use to play sounds
[self makeEngineConnections];
[self startEngine];
}
-(void) loadSoundFontInstrument {
if (_sampler != nil) {
NSString* instrument = [[GameData sharedGameData].settings valueForKey:@"instrument"]; //decides on what sound font file to use
NSURL *piano = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:instrument ofType:@"sf2"]];
[_sampler loadSoundBankInstrumentAtURL:piano program:0 bankMSB:0x79 bankLSB:0 error:nil];
}
else
NSLog(@"ERROR: Sampler has not been initialized");
}
-(void)makeEngineConnections {
[_engine attachNode:_sampler];
[_engine connect:_sampler to:_mixer format:[_sampler outputFormatForBus:0]];
}
-(void)startEngine {
[_engine startAndReturnError:nil];
}