Hello,
I am trying to make my project clean and so I am looking for memory leaks reported by DirectX debug driver. The problem has two parts:
1) if I set a "Break on AllocId" in DX configuration with Id obtained from previous program run where DX reported memory leak, project is stopped on absolutely unrelated piece of code - is it possible that it takes some time for DX to stop it when it catches a problem how can i find the exact location could this be because of I am running it multithreaded
2) I discovered that even such calls as SetStreamSource, SetIndices, etc. throw a memory leak if they are not "unloaded" by the same call with some default value
for example:
-----
pDevice->SetIndices( pBuffer );
...
----- THIS THROWS A MEMORY LEAK
-----
pDevice->SetIndices( pBuffer );
...
pDevice->SetIndices( NULL );
----- THIS DOESN'T THROW A MEMORY LEAK
I found and removed most of these so called leaks, but I have one with SetFVF() and I am not able to remove it for my life. Does anybody know which value should be used there For example:
SetFVF( D3DFVF_XYZ | D3DFVF_DIFFUSE ); // 2 objects unallocated
SetFVF( 0 ); // this won't help, moreover it produces 2 more leaks for unallocated objects
Please, does anybody know how to get rid of these
Thanks in advance.
//rem
PS: I am using D3DXFONT for drawing text on the screen. If I remove the drawing call (pFont->DrawText()) there's 8 memory leaks less than with this call. I think I am not able to remove these, am I

Preventing memory leaks
Augusto Ruiz
Debugging memory leaks is always a tedious and painful experience - so my best advice is to just write good code that never leaks
There is a thread on the DIRECTXDEV mailing list at the moment about interpretting/debugging memory leaks - it starts here. You might be able to pick up a few ideas from that.
Some general things...
Only those objects that are COM-based need to be AddRef()'d and Release()'d - so your mention of FVF (which is just a DWORD) can't cause a leak. It is possible to get a lot of "echoes" when debugging this sort of thing - memory leaks have a tendancy to come from something very simple yet manifest themselves in the most weird places.
Calls that take a COM-based instance (e.g. SetIndices() and SetTexture()) should internally AddRef() and Release() them. However, there is a heirarchy of how/where objects are created - thus a failure to AddRef()/Release() at a high level (e.g. your program) can actually seem as if it failed at a lower level (inside the parent object/class).
D3DX is a layer on top of D3D, thus any leaks with D3DX objects (e.g. ID3DXMesh and ID3DXFont) won't be directly reported as leaked - their internal objects will. Failing to release ID3DXFont might actually manifest itself as a leaked IDirect3DTexture9 (or whatever else is used internally).
You should try using PIX - run a full stream capture, and then jump to the very last frame. Open up the resource viewer (forget its exact name) and check for any resources that are still marked as "Alive" - these are your leaked objects.
hth
Jack
Curtiss12345
Purely for future reference purposes, this same thread was posted on GameDev.net here. If the content in this thread doesn't directly help out, it could be worth checking out what the other one contains
Cheers,
Jack