Reputation: 335
We have a native C++ application running on Windows which uses Component Object Model (COM) as a client. In our case, we can using IUIAutomation
. Unfortunately, we have memory leaks in our code that aren't showing up using our basic memory debugging approaches:
_CRTDBG_MAP_ALLOC
- http://msdn.microsoft.com/en-us/library/x98tx3cf.aspx
How can we debug memory leaks in our executable related to our misuse of COM/IUnknown/and memory allocations across the COM barrier?
We are flexible on tools/libraries/etc. We are on Windows 8 running Visual Studio 2012.
Upvotes: 3
Views: 1272
Reputation: 5458
It might have something to do with BSTR caching.
Basically, OLE caches all BSTR objects allocated in a process to allow it to pool together strings. As a result, these strings are effectively leaked "on purpose". The KB article indicates that the cache is cleared when the OLEAUT32.DLL's DLL_PROCESS_DETACH logic is run, which is good to know, but didn't help me to debug my BSTR leak – I could still be leaking BSTRs.
The good thing is that you can disable this caching by setting the environment variable OANOCACHE=1
and rebooting. Or you can call SetOaNoCache within your program without affecting your whole operating system.
Upvotes: 1