I have an instance where a class creates a DX9 texture via

HRESULT hr = D3DXCreateTexture (m_D3DDevice, 

Where m_texture is IDirect3DTexture9* and hr = S_OK after creation.

But when I come to cleaning it up in the destructor via

if (m_texture != NULL)
    hr = m_texture->Release();

hr = S_FALSE

Why would it fail to release a texture?


1 Answer 1


Release does not return an HRESULT, it returns a ULONG. That ULONG is the new reference count on the object (after the release).

hr == S_FALSE in your code because Release is returning 1 (which is what S_FALSE is defined as), which means there's one pending reference count to the object after you release it (that's not necessarily a problem, it could be an internal D3D reference).

The return code from Release is intended only for diagnostic purposes. But, tldr, it's not failing, it's working fine.

  • \$\begingroup\$ Hmm, HRESULT on other Release() calls returns S_OK though. and when I comment out m_texture->Release(), I don't get a memory error when the program is closed. \$\endgroup\$
    – unknownSPY
    Apr 20, 2016 at 19:09
  • \$\begingroup\$ Release() does not result an HRESULT! Stop casting it to one. It's just returns number, and one you cannot meaningfully rely on. It's perfectly valid for Release() to return 0, 1, 500, 128374, whatever. It simply returns to you the number of outstanding references after release, those references may not have been created by you at all. As long you are pairing every AddRef (or every create) with a Release, you're fine. If you've enabled memory leak tracking in D3D and aren't getting warnings about unreleased objects, you're fine. \$\endgroup\$
    – user1430
    Apr 20, 2016 at 19:14
  • \$\begingroup\$ Save yourself a lot of pain and stop using raw pointers to COM interfaces. Use Microsoft::WRL::ComPtr so you don't have to worry about manual AddRef and Release counts. \$\endgroup\$ Jul 27, 2016 at 20:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .