I have a multithread COM application which uses WASAPI
IAudioClient. I create the client in the main thread and read the audio data in a child thread. The audio client is declared as a class member:
On changing the audio devices (like unplugging headphones) I want to activate another audio client but using the same COM object, so I call
Activate on the same COM object for the audio client:
HRESULT hr = mmDevice->Activate( __uuidof(IAudioClient), CLSCTX_ALL, NULL, (void**)&audioClient );
Because I need to have a null COM variable before creating a new object, I get it. But if I use
audioClient.Release() before that
Activate function, my application hangs right on releasing.
I’m ok with having that assert (moreover, it’s only in Debug). But the question is can I just create a new object without releasing the old one, will it introduce any leaks or something? Or should I release the object somehow differently to avoid hanging?
Source: Windows Questions