AVAudioEngine continues to perform despite view controller being dismissed
<p>I have my code set up with a playernode mixernode and an input node. I have also set it up to deal with interruptions or specific changes in functionality.</p>

<p>However with these changes comes a big problem and that is that if the view controller is dismissed not only does it no longer free up memory for my app, but the playernode continues to play. If i go back to the view with the player node and press stop it doesn't work. I can even activate the player again and it will play along with the player that can't be stopped.</p>

<pre><code>-(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:&amp;error];
_playerLoopBuffer = [[AVAudioPCMBuffer alloc] initWithPCMFormat:[hiphopOneFile processingFormat] frameCapacity:(AVAudioFrameCount)[hiphopOneFile length]];
success = [hiphopOneFile readIntoBuffer:_playerLoopBuffer error:&amp;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];


}
</code></pre>

<p>The problem area lies in the bottom area of the code where I attempt to get notifications from the engine if there's a hardware config change. If I remove this code, when the view is dismissed all the memory the engine is using will be also. But this also means that if say someone plugs in headphones the app crashes.
So I need the code you see but I need to change it so that if the view is dismissed the app will release the memory being used.</p>

<p>Any advice?</p>