When to use Release method?

Viewed 132

I'm creating a "mixer" application that controls volumes of audio sessions and endpoints. My question is, does calling Release method on IMMDevice invalidate previously acquired IAudioEndpointVolume reference? In my program it looks something like this:

IMMDevice *device;
IMMDeviceEnumerator *deviceEnumerator;
IMMDeviceCollection *deviceCollection;
IAudioEndpointVolume *audioEndpoint;

... // Initializing device, deviceEnumerator and deviceCollection

// for cycle {
    ...
    deviceCollection->Item(i, &device);
    device->Activate(IID_IAudioEndpointVolume, CLSCTX_ALL, NULL, (void**)&audioEndpoint);
    device->Release();  // Will this cause UB in the next line?
    audioEndpoint->GetMasterVolume(&volume);
    ...
//}

Should I use Release method like this or only after Releasing audioEndpoint?

0 Answers
Related