Click to See Complete Forum and Search --> : GetChildContainer and memory leak


Tronx
April 7th, 2008, 02:51 PM
Hello. I'm hoping somone here can help me with a problem that has been driving me nuts for 2 days. It has to do with DirectX.

I'm polling DxDiag for monitor information. To find a leak that I noticed, I've tracked it down to a portion of the code that calls GetChildContainer. Every time I make this call there are about two handles leaked (and, subsequentially, memory also). I release all objects but still the problem exists.

Here is the setup. Includes are (other than the standard):
#include <dxdiag.h>
#include <d3dx9.h>
#include <process.h>

#pragma comment (lib, "dxguid.lib")
For testing I set up the message handler this way:
case WM_KEYDOWN:
if ( hTimer == TRUE )
KillTimer( hWnd, 9988 );
else
SetTimer( hWnd, 9988, 5000, 0 );

hTimer = !hTimer;
break;
case WM_TIMER:
DXDiagTest();
break;
And DxDiagTest():
void DXDiagTest () {

IDxDiagProvider* Provider = NULL;
IDxDiagContainer* Root = NULL;
IDxDiagContainer* Container = NULL;


HRESULT CoInit = CoInitialize( NULL );

HRESULT hr = CoCreateInstance( CLSID_DxDiagProvider,
NULL,
CLSCTX_INPROC_SERVER,
IID_IDxDiagProvider,
( LPVOID* ) &Provider );

DXDIAG_INIT_PARAMS InitParams;
ZeroMemory( &InitParams, sizeof( DXDIAG_INIT_PARAMS ) );

InitParams.dwSize = sizeof( DXDIAG_INIT_PARAMS );
InitParams.dwDxDiagHeaderVersion = DXDIAG_DX9_SDK_VERSION;
InitParams.bAllowWHQLChecks = FALSE;
InitParams.pReserved = NULL;

Provider -> Initialize( &InitParams );
Provider -> GetRootContainer( &Root );
Root -> GetChildContainer( _T( "DxDiag_DisplayDevices" ), &Container );

SAFE_RELEASE( Container );
SAFE_RELEASE( Root );
SAFE_RELEASE( Provider );
if ( CoInit ) { CoUninitialize(); }

return;
};

When I execute that and watch it in Task Manager the open handle count fluctuates a lot but steadily increases. Diddo for the memory useage.

If there is a way to release any object that might have been created by the GetChildContainer call I would love to know about it :)

I'm new to C++ and DirectX in general, so it is possible that I'm missing something obvious. The rest of the program runs fines until I hit that portion of code above, so I'm pretty sure it is in that call.

Could someone give me a clue? :D