Memory Leak Detected

Jul 21, 2016 at 5:45 AM

I'm using DirectX Tool Kit Library to load a texture and in my declaration of EffectFactory Visual Studio detect a "Memory Leak"
//Here is detected the leak
unique_ptr<EffectFactory> pEffectFactory = unique_ptr<EffectFactory>(new EffectFactory(D3D11RENDERER->GetDevice())
pEffectFactory->CreateTexture(L"head.jpg", D3D11RENDERER->GetContext(), ppTexture);
Is there any wrong in my code??

Jul 26, 2016 at 7:25 AM
I would focus on the ppTexture parameter. Are you using Microsoft::WRL::ComPtr?
Jul 28, 2016 at 6:24 AM

No, it is a normal pointer.

I changed the load textures. Now I'm using DirectXTex and it works well, the memory leak disapears but I would like to know why Visual C++ detect a memory leak with DirectX Tool Kit

Jul 29, 2016 at 7:51 AM
Edited Jul 29, 2016 at 7:52 AM
There's no reason to use DirectXTex here. DirectX Tool Kit is the better option for runtime use per this blog post.

From the tiny snippet of code you provided, I can't tell why you had a memory leak, but the code looks pretty odd as you've written it. Normally you create the EffectFactory instance as a member variable and keep it around, something like:
// in your class's header file
std::unique_ptr<DirectX::EffectFactory> m_effectFactory;

// in your class' implementation file
m_effectFactory = std::make_unique<EffectFactory>(D3D11RENDERER->GetDevice());
You are probably just using the smart-pointer system incorrectly.

You don't need to use an EffectFactory at all to load a texture as you can directly use the DDSTextureLoader or WICTextureLoader functions. The only reason to use EffectFactory is have it deal with caching by file name.

You should have a run through the tutorials and see if helps clarify your understanding.