[DX9] Everything I touch is leaking memory, and I don't know why

Started by
8 comments, last by KanTeH 13 years, 3 months ago
I recently started using the dx9 debug output, and after watching it's endless spew of memory leaks that it reports after the program exits, I decided to track them down and clean it up.

My project is in the very early stages at this point, so it's not very complex and this should be easy. Unfortunately no matter what I try I can't seem to stop the leaks, which makes me think I have some serious misunderstanding about how this COM stuff all works.

I'm tracking down the leaks using break on allocID, but I just can't explain the things it comes up with.

Before I post my main codes, note if you see this method, it's just returning a pointer, so shouldn't be a problem. (its for encapsulation for cross api)
LPDIRECT3DDEVICE9 GfxDevice::GetD3DDevice(){return _d3dDevice;}


Here's one of the places it comes up with, I create a vertex declaration and then free it two lines later. Yet it still comes up in the memory leak report. Isn't release what I'm supposed to be doing to free this?
gfxDev.GetD3DDevice()->CreateVertexDeclaration(&_d3dVertexDeclarationDefinition[0],&_d3dVertexDeclaration);gfxDev.GetD3DDevice()->SetVertexDeclaration(_d3dVertexDeclaration);_d3dVertexDeclaration->Release();


It's even leaking on this line, I don't see why this would alloc any memory at all, much less leak anything.
hr = gfxDev.GetD3DDevice()->DrawPrimitive(d3dtype, startVertex, numPrims);


Another leak in Present, why?
_d3dDevice->Present(NULL, NULL, NULL, NULL);


Nothing else that I release seems to matter either. For example I would have a class that encapsulates a vertex shader, which is released in the destructor. I only have one vertex shader in the program, I watch it release with a destructor breakpoint when the program closes, and then afterwards it still reports it as leaking.
GfxVertexShader::~GfxVertexShader(){	_shader->Release();}bool GfxVertexShader::Compile(){...	_gfxDev->GetD3DDevice()->CreateVertexShader((DWORD*)shaderSource->GetBufferPointer(),&_shader);...}


Am I just missing something fundamental about how this is supposed to work?

My log for anyone curious:
The thread 'Win32 Thread' (0xc28) has exited with code 0 (0x0).Direct3D9: :====> ENTER: DLLMAIN(5abca170): Process Detach 00001370, tid=00000fe0Direct3D9: (INFO) :MemFini!Direct3D9: (ERROR) :Memory still allocated!  Alloc count = 134Direct3D9: (ERROR) :Current Process (pid) = 00001370Direct3D9: (ERROR) :Memory Address: 01f207f4 lAllocID=1 dwSize=00004bc4, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f253ec lAllocID=2 dwSize=0000031c, ReturnAddr=5abcc90a (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2573c lAllocID=3 dwSize=00000c28, ReturnAddr=5abd29d1 (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01def30c lAllocID=5 dwSize=0001f270, ReturnAddr=5abda268 (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e0e5b4 lAllocID=6 dwSize=00001fa4, ReturnAddr=5abcb244 (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e1058c lAllocID=7 dwSize=00000360, ReturnAddr=5abcb2d1 (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e10924 lAllocID=8 dwSize=00000018, ReturnAddr=5abcb32a (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01dd0064 lAllocID=24 dwSize=00001d1c, ReturnAddr=5abbfd1b (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e10974 lAllocID=25 dwSize=00000360, ReturnAddr=5abbfd61 (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e10d0c lAllocID=26 dwSize=00000018, ReturnAddr=5abbfdb1 (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2681c lAllocID=27 dwSize=0000031c, ReturnAddr=5abcc90a (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01dd1db4 lAllocID=28 dwSize=00000c28, ReturnAddr=5abd29d1 (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e10fcc lAllocID=30 dwSize=0001a0cc, ReturnAddr=5abda268 (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01dd2a14 lAllocID=31 dwSize=00001fa4, ReturnAddr=5abcb244 (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e2b0cc lAllocID=32 dwSize=00000610, ReturnAddr=5abcb2d1 (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e10d5c lAllocID=33 dwSize=00000018, ReturnAddr=5abcb32a (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01dd49ec lAllocID=35 dwSize=00001d1c, ReturnAddr=5abbfd1b (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e2b714 lAllocID=36 dwSize=00000610, ReturnAddr=5abbfd61 (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e10dac lAllocID=37 dwSize=00000018, ReturnAddr=5abbfdb1 (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01dd673c lAllocID=45 dwSize=00000c28, ReturnAddr=5abd29d1 (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e10dfc lAllocID=46 dwSize=00000020, ReturnAddr=5abdc32c (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01dd739c lAllocID=47 dwSize=00001fa4, ReturnAddr=5abcb244 (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01dd9374 lAllocID=48 dwSize=00000360, ReturnAddr=5abcb2d1 (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e10e54 lAllocID=49 dwSize=00000018, ReturnAddr=5abcb32a (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01dd970c lAllocID=51 dwSize=00003ea8, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e2bd5c lAllocID=52 dwSize=00000198, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e10ea4 lAllocID=53 dwSize=00000030, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01ddd5ec lAllocID=54 dwSize=00001020, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01dde644 lAllocID=55 dwSize=00000858, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e2bf2c lAllocID=56 dwSize=00000098, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f26b6c lAllocID=57 dwSize=0000007c, ReturnAddr=5abdd617 (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f26c1c lAllocID=58 dwSize=00000024, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f26c74 lAllocID=59 dwSize=00000098, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f26d44 lAllocID=60 dwSize=0000007c, ReturnAddr=5abdd617 (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f26df4 lAllocID=61 dwSize=00000044, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f26e6c lAllocID=62 dwSize=00000024, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f26ec4 lAllocID=63 dwSize=000000a8, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e2c004 lAllocID=64 dwSize=0002b330, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f26fa4 lAllocID=65 dwSize=0000002c, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e5736c lAllocID=66 dwSize=00000028, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e573cc lAllocID=67 dwSize=00000420, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e57824 lAllocID=68 dwSize=00000030, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e5788c lAllocID=69 dwSize=00000030, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01ddeed4 lAllocID=70 dwSize=00001020, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e578f4 lAllocID=71 dwSize=00000120, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e57a4c lAllocID=72 dwSize=00000060, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01ddff2c lAllocID=73 dwSize=00000e20, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e57ae4 lAllocID=74 dwSize=00000120, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e57c3c lAllocID=75 dwSize=00000060, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01de0d84 lAllocID=76 dwSize=000003ec, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e57cd4 lAllocID=77 dwSize=00000050, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e57d5c lAllocID=78 dwSize=00000050, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e57de4 lAllocID=79 dwSize=00000050, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e57e6c lAllocID=80 dwSize=00000050, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e57ef4 lAllocID=81 dwSize=00000048, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e57f74 lAllocID=82 dwSize=00000054, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01de11a4 lAllocID=83 dwSize=00000048, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01de1224 lAllocID=84 dwSize=000000c0, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01de131c lAllocID=85 dwSize=0000007c, ReturnAddr=5abdd617 (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01de13cc lAllocID=86 dwSize=000000c0, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01de14c4 lAllocID=87 dwSize=0000007c, ReturnAddr=5abdd617 (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01de1574 lAllocID=88 dwSize=000000c0, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01de166c lAllocID=89 dwSize=0000007c, ReturnAddr=5abdd617 (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01de171c lAllocID=90 dwSize=000000b0, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01de1804 lAllocID=91 dwSize=0000007c, ReturnAddr=5abdd617 (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01de18b4 lAllocID=92 dwSize=00000050, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01de193c lAllocID=93 dwSize=0000002c, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01de199c lAllocID=94 dwSize=00000028, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01de19fc lAllocID=95 dwSize=0000002c, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01de1a5c lAllocID=96 dwSize=0000517c, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01de6c0c lAllocID=97 dwSize=00001020, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01de7c64 lAllocID=98 dwSize=0000003c, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01de7cd4 lAllocID=99 dwSize=00004020, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01debd2c lAllocID=100 dwSize=0000003c, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01debd9c lAllocID=101 dwSize=0000183c, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e58004 lAllocID=102 dwSize=0000fab8, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e67af4 lAllocID=103 dwSize=00000068, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e67b94 lAllocID=104 dwSize=00000140, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e67d0c lAllocID=105 dwSize=0000003c, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f27004 lAllocID=106 dwSize=00004020, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e67d7c lAllocID=107 dwSize=0000003c, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01ded60c lAllocID=108 dwSize=0000183c, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01deee7c lAllocID=109 dwSize=0000021c, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2b05c lAllocID=110 dwSize=00000224, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e67dec lAllocID=111 dwSize=0000003c, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e67e5c lAllocID=112 dwSize=00000060, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e67ef4 lAllocID=113 dwSize=0000009c, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01def0cc lAllocID=114 dwSize=00000050, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01def154 lAllocID=115 dwSize=00000038, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 04c0003c lAllocID=116 dwSize=00182380, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01def1c4 lAllocID=117 dwSize=000000a0, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01def29c lAllocID=118 dwSize=0000002c, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2b2b4 lAllocID=119 dwSize=00000040, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2b32c lAllocID=120 dwSize=00000040, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2b3a4 lAllocID=121 dwSize=00000040, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2b41c lAllocID=122 dwSize=00000060, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2b4b4 lAllocID=123 dwSize=00000030, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2b51c lAllocID=124 dwSize=00000b38, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2c08c lAllocID=125 dwSize=00001020, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2d0e4 lAllocID=126 dwSize=00000120, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2d23c lAllocID=127 dwSize=00000060, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2d2d4 lAllocID=128 dwSize=00001020, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2e32c lAllocID=129 dwSize=00000120, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2e484 lAllocID=130 dwSize=00000060, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2e51c lAllocID=131 dwSize=00000420, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2e974 lAllocID=132 dwSize=000000e4, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2ea8c lAllocID=133 dwSize=00000028, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2eaec lAllocID=134 dwSize=000000b8, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2ebdc lAllocID=135 dwSize=0000005c, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2ec6c lAllocID=136 dwSize=0000007c, ReturnAddr=5abdd617 (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2ed1c lAllocID=137 dwSize=00000040, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2ed94 lAllocID=199 dwSize=000008b4, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2f67c lAllocID=200 dwSize=00000144, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2f7f4 lAllocID=201 dwSize=00000034, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2fb34 lAllocID=209 dwSize=0000002a, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e67fc4 lAllocID=211 dwSize=000006fc, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2f85c lAllocID=262 dwSize=000000e0, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2f974 lAllocID=263 dwSize=0000005c, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2fb94 lAllocID=270 dwSize=00000120, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e686f4 lAllocID=271 dwSize=00010020, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2fa04 lAllocID=272 dwSize=00000024, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2fa5c lAllocID=273 dwSize=0000007c, ReturnAddr=5abdd617 (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2fcec lAllocID=274 dwSize=0000003c, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2fd5c lAllocID=275 dwSize=00000040, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01f2fdd4 lAllocID=276 dwSize=00000010, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e787bc lAllocID=280 dwSize=00000120, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e78914 lAllocID=281 dwSize=00000024, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e7896c lAllocID=282 dwSize=0000007c, ReturnAddr=5abdd617 (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e78a1c lAllocID=283 dwSize=0000003c, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e78a8c lAllocID=284 dwSize=000000c0, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e78b84 lAllocID=285 dwSize=0000007c, ReturnAddr=5abdd617 (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e78c34 lAllocID=286 dwSize=0000007c, ReturnAddr=5abe5d24 (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e78ce4 lAllocID=686 dwSize=000001a0, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Memory Address: 01e78ebc lAllocID=688 dwSize=00000038, ReturnAddr=5abc99aa (pid=00001370)Direct3D9: (ERROR) :Total Memory Unfreed From Current Process = 2328110 bytesDirect3D9: :====> EXIT: DLLMAIN(5abca170): Process Detach 00001370
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Advertisement
Hehe! Keep at it - it *IS* possible to clean all of them up. Think of it like this....all the sub-COM objects belong to IDirect3DDevice9 ... so if you've forgotten to bring the REF count for one of them to ZERO before you exit then your D3DDevice itself can't be released to ZERO REFERENCES either ... and none of the objects it owns can be properly released either ... hence the storm of memory leaks ;) Nearly everything has a Release() method that you should call .. especially IDirect3DDevice9 ... the break on alloc ID thing doesn't work too well either ... the first alloc ID is almost always your device and the last one is not generally the one you are forgetting to release.
I don't have time to really analyse your code at the moment (Xmas shopping todo!), but all I can say is, firstly, just HOW are you identifying the memory leaks?

Usually, one of the best ways I've found is to take a snapshot of the heap just BEFORE the test code, and then take another snapshot of the heap right AFTER that code to check for an immediate memory leak right there right then.

You don't seem to be using any memory leak checking mechanism directly in your code from what I can see so, this might be a better approach to give you a more accurate report.

Remember, DirectX is intentionally "black-box" technology, in that you have NO idea on how memory is structured, allocated or deal located. If a whole load of static variables are being set up on the heap, then these resources will not get released until program exit.

That said though, this will also fool the memory checking technique I've described above unless such code is written, say, in a DLL. Checking the heap status before the DLL is loaded, and then again after the OS unloads it, is the way I tend to use such memory checking techniques.

Second point, you should really use some sort of smart wrapper to encapsulate DirectX interfaces. Boosts intrusive_ptr serves as an excellent choice and I would advise that you look into this. Saves you having to remember to release your interfaces when they are no longer needed (i.e. when they go out of scope).
Quote:Original post by CodeStorm
just HOW are you identifying the memory leaks?


It's the directx sdk debug output. It is very explicit and says "This line you have called is causing a memory leak."

I thought a little more about it, and I think my problem is that I was thinking I could release an object that is still in use by another object.

So for example this:
gfxDev.GetD3DDevice()->CreateVertexDeclaration(&_d3dVertexDeclarationDefinition[0],&_d3dVertexDeclaration);gfxDev.GetD3DDevice()->SetVertexDeclaration(_d3dVertexDeclaration);_d3dVertexDeclaration->Release();


Causes a leak on the last loop before exiting, because the _d3dVertexDeclaration is still "Set" when the program exits. Probably the same thing for my vertex and fragment shaders, they are still "bound" when I release them at the end of the program, so maybe they are not releasing?

I guess to get a clean bill of health from DX leak report I need to go through and unbind any objects I have created? Unbind my shaders, unbind the vertex declarations, etc. Does that sound right?


[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
It's just ref counting. If you make a COM object's ref count increase you need to make it decrease before it can be deleted and release a ref count on all the objects it owns. One clog will plug up the whole sink so to speak. CodeStorm's advice is useless for tracking DirectX "leaks" by the way ... but it will work for HEAP memory. PIX can help you figure out what's still alive at program exit and who created it (you or D3D9).
The usual cause for memory leaks like this is calling GetBackBuffer(), GetSurfaceLevel(), or some similar Get*() call, and not Release()ing the interface returned.

I find the easiest way to track the errors down is to just comment out code until the problem goes away, then narrow it down from there.
Quote:Original post by Steve_Segreto
CodeStorm's advice is useless for tracking DirectX "leaks" by the way ... but it will work for HEAP memory.


Mmmm... This is the approach that I've been using in my code. I just assumed DirectX utilized heap memory internally in conjunction with other device specific memory, which is of course much harder to track without using DirectX (or some other 3rd party software).

In terms of being able to detect memory leaks due to unreleased objects alone (putting aside, say, video memory which would have been deallocated anyway if the object was released normally), I just assumed it would be possible to detect leaks in the heap footprint of the object.

Anyway, it seems a fair bet that the memory leaks which are causing the OPs problems are down to objects not being referenced counted properly. Using a wrapper to automate Release calls should help to reduce such errors and make for cleaner, more robust code (especially in the light of an exceptions being raised).
Quote:Original post by Evil Steve
The usual cause for memory leaks like this is calling GetBackBuffer(), GetSurfaceLevel(), or some similar Get*() call, and not Release()ing the interface returned.

I find the easiest way to track the errors down is to just comment out code until the problem goes away, then narrow it down from there.


Unfortunately this is really the best advice for this kind of problem. I completely agree - comment out parts of your code until the leaks disappear and then zero in on the culprit.
Steve and Steve have it right.

And.. as you continue to develop your project, compile and run it every 30 to 50 lines of code added. It takes maybe a minute but you'll know immediately that you did something incorrectly. Ten or fifteen minutes of compiling/running in an evening of programming is better than hours and hours spent finding a problem in several hundred lines of code.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

ive had recently similar problems. Ive added macros to count myself what i take and giveback from directx, similar to smartpointers but only in debugmode.
Well directX was right, because i assumed that deconstructors get always called.
But if ur object is member of an other object it doesnt get called automaticly.

Now to directX, dont thrust the debugbreakoutputs from directX! I got breaks on alloc ids which i didnt unterstand aswell and where i was sure im releasing this objects.

This topic is closed to new replies.

Advertisement