   Memory Leek
  Ok, so I thought I'd be all smarty pants and use CComPtr to hold my D3D objects.  It turns out though, that I have memory leaks from doing so.  I'm only holding the following (I'm just starting the framework):// D3D InterfacesCComPtr<IDirect3D9> MyD3D9;CComPtr<IDirect3DDevice9> MyDevice;Nothing else.  That is, I'm creating an IDirect3D9 and an IDirect3DDevice9 and that's all.  I've allocated nout else.  I can see the destructor on the class that owns the CComPtr getting called on program shut-down.  I know I'm not doing anything daft like getting references to the interfaces twice (the method that does this has a guard on it to ensure that is not allowed).  Yet D3D debugger output says the following (below).  Anyone have an explanation?Direct3D9: :====> ENTER: DLLMAIN(00a6e6e0): Process Detach 00001198, tid=000016a8Direct3D9: (INFO) :MemFini!Direct3D9: (WARN) :Memory still allocated!  Alloc count = 7Direct3D9: (WARN) :Current Process (pid) = 00001198Direct3D9: (WARN) :Memory Address: 00377000 lAllocID=1 dwSize=000047f8, (pid=00001198)Direct3D9: (WARN) :  Stack Back TraceDirect3D9: (ERROR) :    [0] : Address 00A6E4CBDirect3D9: (ERROR) :    [1] : Address 00A6E59BDirect3D9: (ERROR) :    [2] : Address 00A6E440Direct3D9: (ERROR) :    [3] : Address 00A62DB4Direct3D9: (ERROR) :    [4] : Address 4FDFAF2EDirect3D9: (ERROR) :    [5] : Address 00415200Direct3D9: (ERROR) :    [6] : Address 00411F77Direct3D9: (ERROR) :    [7] : Address 00411BFFDirect3D9: (ERROR) :    [8] : Address 00417579Direct3D9: (ERROR) :    [9] : Address 004172DDDirect3D9: (ERROR) :    [10] : Address 7C817077Direct3D9: (ERROR) :    [11] : Address 00000000Direct3D9: (ERROR) :    [12] : Address 00000000Direct3D9: (ERROR) :    [13] : Address 00000000Direct3D9: (ERROR) :    [14] : Address 00000000Direct3D9: (ERROR) :    [15] : Address 00000000Direct3D9: (WARN) :Memory Address: 0037df58 lAllocID=20 dwSize=000017a0, (pid=00001198)Direct3D9: (WARN) :  Stack Back TraceDirect3D9: (ERROR) :    [0] : Address 00A650D4Direct3D9: (ERROR) :    [1] : Address 00A65EBFDirect3D9: (ERROR) :    [2] : Address 00A665F8Direct3D9: (ERROR) :    [3] : Address 00A62DD5Direct3D9: (ERROR) :    [4] : Address 4FDFAF2EDirect3D9: (ERROR) :    [5] : Address 00415200Direct3D9: (ERROR) :    [6] : Address 00411F77Direct3D9: (ERROR) :    [7] : Address 00411BFFDirect3D9: (ERROR) :    [8] : Address 00417579Direct3D9: (ERROR) :    [9] : Address 004172DDDirect3D9: (ERROR) :    [10] : Address 7C817077Direct3D9: (ERROR) :    [11] : Address 00000000Direct3D9: (ERROR) :    [12] : Address 00000000Direct3D9: (ERROR) :    [13] : Address 00000000Direct3D9: (ERROR) :    [14] : Address 00000000Direct3D9: (ERROR) :    [15] : Address 00000000Direct3D9: (WARN) :Memory Address: 0037d720 lAllocID=21 dwSize=00000018, (pid=00001198)Direct3D9: (WARN) :  Stack Back TraceDirect3D9: (ERROR) :    [0] : Address 00A651C2Direct3D9: (ERROR) :    [1] : Address 00A65EBFDirect3D9: (ERROR) :    [2] : Address 00A665F8Direct3D9: (ERROR) :    [3] : Address 00A62DD5Direct3D9: (ERROR) :    [4] : Address 4FDFAF2EDirect3D9: (ERROR) :    [5] : Address 00415200Direct3D9: (ERROR) :    [6] : Address 00411F77Direct3D9: (ERROR) :    [7] : Address 00411BFFDirect3D9: (ERROR) :    [8] : Address 00417579Direct3D9: (ERROR) :    [9] : Address 004172DDDirect3D9: (ERROR) :    [10] : Address 7C817077Direct3D9: (ERROR) :    [11] : Address 00000000Direct3D9: (ERROR) :    [12] : Address 00000000Direct3D9: (ERROR) :    [13] : Address 00000000Direct3D9: (ERROR) :    [14] : Address 00000000Direct3D9: (ERROR) :    [15] : Address 00000000Direct3D9: (WARN) :Memory Address: 0037f768 lAllocID=22 dwSize=00000160, (pid=00001198)Direct3D9: (WARN) :  Stack Back TraceDirect3D9: (ERROR) :    [0] : Address 00A6679FDirect3D9: (ERROR) :    [1] : Address 00A62DD5Direct3D9: (ERROR) :    [2] : Address 4FDFAF2EDirect3D9: (ERROR) :    [3] : Address 00415200Direct3D9: (ERROR) :    [4] : Address 00411F77Direct3D9: (ERROR) :    [5] : Address 00411BFFDirect3D9: (ERROR) :    [6] : Address 00417579Direct3D9: (ERROR) :    [7] : Address 004172DDDirect3D9: (ERROR) :    [8] : Address 7C817077Direct3D9: (ERROR) :    [9] : Address 00000000Direct3D9: (ERROR) :    [10] : Address 00000000Direct3D9: (ERROR) :    [11] : Address 00000000Direct3D9: (ERROR) :    [12] : Address 00000000Direct3D9: (ERROR) :    [13] : Address 00000000Direct3D9: (ERROR) :    [14] : Address 00000000Direct3D9: (ERROR) :    [15] : Address 00000000Direct3D9: (WARN) :Memory Address: 0037d7a8 lAllocID=23 dwSize=00000044, (pid=00001198)Direct3D9: (WARN) :  Stack Back TraceDirect3D9: (ERROR) :    [0] : Address 00A6E4CBDirect3D9: (ERROR) :    [1] : Address 00A6E59BDirect3D9: (ERROR) :    [2] : Address 00A6E440Direct3D9: (ERROR) :    [3] : Address 00ADD2D5Direct3D9: (ERROR) :    [4] : Address 00ADB696Direct3D9: (ERROR) :    [5] : Address 00A62E2EDirect3D9: (ERROR) :    [6] : Address 4FDFAF2EDirect3D9: (ERROR) :    [7] : Address 00415200Direct3D9: (ERROR) :    [8] : Address 00411F77Direct3D9: (ERROR) :    [9] : Address 00411BFFDirect3D9: (ERROR) :    [10] : Address 00417579Direct3D9: (ERROR) :    [11] : Address 004172DDDirect3D9: (ERROR) :    [12] : Address 7C817077Direct3D9: (ERROR) :    [13] : Address 00000000Direct3D9: (ERROR) :    [14] : Address 00000000Direct3D9: (ERROR) :    [15] : Address 00000000Direct3D9: (WARN) :Memory Address: 011132e8 lAllocID=122 dwSize=00000420, (pid=00001198)Direct3D9: (WARN) :  Stack Back TraceDirect3D9: (ERROR) :    [0] : Address 00A6E4CBDirect3D9: (ERROR) :    [1] : Address 00A6E59BDirect3D9: (ERROR) :    [2] : Address 00A6E440Direct3D9: (ERROR) :    [3] : Address 00ADE3A2Direct3D9: (ERROR) :    [4] : Address 00ADEED6Direct3D9: (ERROR) :    [5] : Address 00ADEDF2Direct3D9: (ERROR) :    [6] : Address 00ADE1C6Direct3D9: (ERROR) :    [7] : Address 004153EADirect3D9: (ERROR) :    [8] : Address 00411F77Direct3D9: (ERROR) :    [9] : Address 00411BFFDirect3D9: (ERROR) :    [10] : Address 00417579Direct3D9: (ERROR) :    [11] : Address 004172DDDirect3D9: (ERROR) :    [12] : Address 7C817077Direct3D9: (ERROR) :    [13] : Address 00000000Direct3D9: (ERROR) :    [14] : Address 00000000Direct3D9: (ERROR) :    [15] : Address 00000000Direct3D9: (WARN) :Memory Address: 01113778 lAllocID=123 dwSize=00000420, (pid=00001198)Direct3D9: (WARN) :  Stack Back TraceDirect3D9: (ERROR) :    [0] : Address 00A6E4CBDirect3D9: (ERROR) :    [1] : Address 00A6E59BDirect3D9: (ERROR) :    [2] : Address 00A6E440Direct3D9: (ERROR) :    [3] : Address 00ADE3C0Direct3D9: (ERROR) :    [4] : Address 00ADEED6Direct3D9: (ERROR) :    [5] : Address 00ADEDF2Direct3D9: (ERROR) :    [6] : Address 00ADE1C6Direct3D9: (ERROR) :    [7] : Address 004153EADirect3D9: (ERROR) :    [8] : Address 00411F77Direct3D9: (ERROR) :    [9] : Address 00411BFFDirect3D9: (ERROR) :    [10] : Address 00417579Direct3D9: (ERROR) :    [11] : Address 004172DDDirect3D9: (ERROR) :    [12] : Address 7C817077Direct3D9: (ERROR) :    [13] : Address 00000000Direct3D9: (ERROR) :    [14] : Address 00000000Direct3D9: (ERROR) :    [15] : Address 00000000Direct3D9: (WARN) :Total Memory Unfreed From Current Process = 27028 bytesDirect3D9: :====> EXIT: DLLMAIN(00a6e6e0): Process Detach 00001198   
  There's a very common mistake that people make with CComPtr and Direct3DCreate9, and I suspect you're making the same one. Are you doing something like this?CComPtr<IDirect3D9> MyD3D9;MyD3D9 = Direct3DCreate9(D3D_SDK_VERSION);;  Yes, I am.  Now I think about it, that's adding another reference, isn't it?  I need to allocate it like this: MyPtr(CreateThing)?   ;  Ok, I've got to use attach, apparently, otherwise the interface is leaked.  The answer was all made clear here:http://legalizeadulthood.wordpress.com/2009/01/11/direct3d-programming-tip-3-use-smart-pointers/   ;  Indeed, it works.  No leak :).   