If i don`t release WICFactory(IWICImagingFactory*), What happen?

182 views Asked by At

I'm learning DirectX 2D. When i close my application, i have noticed there is a problem in IWICImagingFactory* type variable.

I use only one IWICImagingFactory* variable in whole program. So i initiate it once when i start program and destroy(release) once when i close my program.

But if i release IWICImagingFactory* variable after call CoUninitialize() function, there is error.

Factorys::~Factorys()
{
    SAFE_RELEASE(mpD2DFactory);
    SAFE_RELEASE(mpWICFactory);
}

↓ Is is korean, meaning : error throw, access violation, "this->mpWICFactory->" is 0x6EEFC7D8

enter image description here

I noticed "this->mpWICFactory->" has problem when i try to release WICFactory after call CoUninitialize(). So i read about CoUninitialize() in here : "https://learn.microsoft.com/en-us/windows/win32/api/combaseapi/nf-combaseapi-couninitialize"

And i read this part in the link : Closes the COM library on the current thread, unloads all DLLs loaded by the thread.

Quetion 1 : When i call CoUninitialize() function, WICfactory is released automatically?

Quetion 2 : Do i have to release WICFactory before call CoUninitialize() function?

1

There are 1 answers

0
mrvux On

Yes, as you mention in the question, CoUninitialize will unload all dependent loaded libraries (WICFactory being one of them). So trying to unload an already unloaded library will get you an AV or another Error.

It's not "really necessary" to release WICFactory, since CoUninitialize will also do it (and since you release when program closes anyway, even if you don't call CoUninitialize the Operating System will do it for you).

However, I strongly recommend that you still release your resources (so yes, release WICFactory, then call CoUninitialize ), having code that knows how to do correct cleanup will always be better in the long term (no matter if you use smart pointers or not, that is up to you).