Search code examples
objective-cciosmemory-managementopenal

Must I release the OpenAL context here?


When setting up OpenAL, the Leaks Instruments tells me that I am leaking alContext here:

alDevice = alcOpenDevice(NULL);
if (!alDevice) {
    return NO;
}

alContext = alcCreateContext(alDevice, 0); // leaking!
if (!alContext) {
    return NO;
}

BOOL success = alcMakeContextCurrent(alContext);
if (!success) {
    return NO;
}

return YES;

Where and how should I release the alContext?


Solution

  • Here's how you would cleanup:

    alcMakeContextCurrent(NULL);
    alcDestroyContext(alContext);
    alcCloseDevice(alDevice);
    

    And you would just call these methods whenever you are done with the context... that depends on your application and how you are using it, but probably in a dealloc somewhere.