• ### Popular Now

• 13
• 16
• 27
• 9
• 9

#### Archived

This topic is now archived and is closed to further replies.

# DI object not releasing properly

This topic is 5368 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Here''s my init code
if(FAILED(pDI->CreateDevice(GUID_SysKeyboard,&pKeyboard,NULL)))
return E_FAIL;

if(FAILED(pKeyboard->SetDataFormat(&c_dfDIKeyboard)))
return E_FAIL;

if(FAILED(pKeyboard->SetCooperativeLevel(hWnd, DISCL_FOREGROUND |
DISCL_NONEXCLUSIVE)))
return E_FAIL;

if(FAILED(pKeyboard->Acquire()))
return E_FAIL; 
And then in my deconstructor I have :
pKeyboard->Unacquire();
SAFE_RELEASE(pKeyboard);

SAFE_RELEASE(pDI)

However when I run the debugger, I get: Direct3D9: (INFO) :MemFini! Direct3D9: (ERROR) :Memory still allocated! Alloc count = 145 Direct3D9: (ERROR) :Current Process (pid) = 00000c9c And I know it''s in reference to the keyboard because if I dont init the keyboard I don''t get the error.

##### Share on other sites
1b) Try turning up the DirectInput slider and enabling output messages for all device types in the control panel and see if you get any more informative output.

1b) As a test I just modified one of the DirectInput samples so that it deliberately didn''t release a device object, and I got a message in my debug spew saying: "DINPUT8: unloaded before all objects released. (cRef:4)".

2a) I find the fact that you''re getting messages regarding DirectInput leaks from Direct3D DLLs highly odd, even unlikely. I suspect there''s something else going on here, maybe to do with some shared control path between your D3D and DI code (e.g. D3D objects only being created when

2b) Unless a particular driver or the ActionMap display stuff is using D3D internally.

3) Is that deconstructor in a class whose object is a global or static variable ? If so, then the deconstructor might be called after WinMain exits.

Try breakpointing the deconstructor (a) to make sure it''s being called [i.e. issues with virtual destructors etc] and (b) to single step the DI calls to see if the messages you see originate there.

4) For debugging purposes, try modifying the SAFE_RELEASE macro you use to check the return value from each Release() call [and maybe causing a breakpoint] to see if there are any references still held by any objects being released. If there are, it indicates that one of the subordinate/child objects wasn''t released or has AddRef''d somewhere

--
Simon O''Connor
ex -Creative Asylum
Programmer &
Microsoft MVP

##### Share on other sites
Are you sure it''s DirectInput? From the debug message it looks like some Direct3D object is not freed up properly.

##### Share on other sites
I know it stopped giving me that error when I commented out the keyboard, but now it is giving me the error still, even though I don''t remember changing anything... Now I have to track this one down. Any suggestions as to how to debug? I know you can set a breakpoint at teh Alloc count it gives me, but when I do that my program crashes because my application loses focus, so I have no way of determing where the error is.