Search code examples
c++visual-c++dllmemory-leaksmsvcrt

How to get the memory usage of DLLs loaded with LoadLibrary()?


My Windows C/C++ application loads approx 30 "plugin" DLL's, one of which currently has a memory leak that i'm trying to track down. Unfortunately i cant just load one DLL at a time as the leak only occurs when the DLLs interact.

I've tried to use GetProcessMemoryInfo() on the handles returned by LoadLibrary(), but that fails with a (permissions?) access error. I've tried to find a way of getting the required permissions for the handle, but have been unable to do so as it appears this can only be done when operating on a process (using OpenProcess() and similar)?

I have also tried using GetProcessMemoryInfo(GetCurrentProcess()) from within the DLLs themselves, but they all report (unsurprisingly i guess) the parent process's memory information.

So i'm out of ideas... is there a way to do this?

Thanks in advance!


Solution

  • CRT functions can be used to locate the memory leak by adding monitors between interaction with DLLs.

    http://www.codeproject.com/Articles/10520/Detecting-memory-leaks-by-using-CRT-diagnostic-fun