Memory management 尽管视图控制器被关闭,AVAudioEngine仍继续运行

Memory management 尽管视图控制器被关闭,AVAudioEngine仍继续运行,memory-management,avfoundation,automatic-ref-counting,avaudiosession,avaudioengine,Memory Management,Avfoundation,Automatic Ref Counting,Avaudiosession,Avaudioengine,我将代码设置为playernode mixernode和输入节点。我还将其设置为处理功能中断或特定更改 然而,这些更改带来了一个大问题,那就是如果视图控制器被关闭,它不仅不再为我的应用程序释放内存,而且playernode继续播放。如果我返回到带有播放器节点的视图并按stop键,它将不起作用。我甚至可以再次激活该播放器,它将与无法停止的播放器一起播放 -(void)setupAudioOne { NSError *error; BOOL success = NO; [self initAVAu

我将代码设置为playernode mixernode和输入节点。我还将其设置为处理功能中断或特定更改

然而,这些更改带来了一个大问题,那就是如果视图控制器被关闭,它不仅不再为我的应用程序释放内存,而且playernode继续播放。如果我返回到带有播放器节点的视图并按stop键,它将不起作用。我甚至可以再次激活该播放器,它将与无法停止的播放器一起播放

-(void)setupAudioOne
{
NSError *error;
BOOL success = NO;

[self initAVAudioSession];

_isSessionInterrupted = NO;
_isConfigChangePending = NO;

_player = [[AVAudioPlayerNode alloc] init];
_inputOne = [[AVAudioInputNode alloc] init];
_setReverb = [[AVAudioUnitReverb alloc] init];



NSURL *hiphopOneURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Hip Hop 1" ofType:@"caf"]];
AVAudioFile *hiphopOneFile = [[AVAudioFile alloc] initForReading:hiphopOneURL error:&error];
_playerLoopBuffer = [[AVAudioPCMBuffer alloc] initWithPCMFormat:[hiphopOneFile processingFormat] frameCapacity:(AVAudioFrameCount)[hiphopOneFile length]];
success = [hiphopOneFile readIntoBuffer:_playerLoopBuffer error:&error];
NSAssert(success, @"couldn't read buffer bitch, %@", [error localizedDescription]);

_isRecording = NO;


[self createEngineAndAttachNodes];
[self makeEngineConnections];

_setReverb.wetDryMix = 75;
[_setReverb loadFactoryPreset:AVAudioUnitReverbPresetMediumHall];

//get notifications from the engine if there's a hardware config change
[[NSNotificationCenter defaultCenter] addObserverForName:AVAudioEngineConfigurationChangeNotification object:nil 
queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
    // if we've received this change rewire everything

    _isConfigChangePending = YES;

    if (!_isSessionInterrupted) {
        NSLog(@"Received a %@ notification!", AVAudioEngineConfigurationChangeNotification);
        NSLog(@"Re-wiring connections and starting once again");
        [self makeEngineConnections];
        [self startEngine];
    }
    else {
        NSLog(@"Session is interrupted, deffering changes");
    }

    //post notification
    if ([self.delegate respondsToSelector:@selector(engineConfigurationHasChanged)]) {
        [self.delegate engineConfigurationHasChanged];
    }
}];
[self startEngine];


}
问题区域位于代码的底部区域,如果硬件配置发生更改,我将尝试从引擎获取通知。如果我删除此代码,当视图被取消时,引擎正在使用的所有内存也将被删除。但这也意味着,如果有人插上耳机,应用程序就会崩溃。 所以我需要你看到的代码,但我需要更改它,以便如果视图被取消,应用程序将释放正在使用的内存

有什么建议吗