I have this problem when running my program:
- The memory consumption increases pretty quickly when one of the functionalities of my program is running.
- I use Performance Monitor and Virtual Leak Detection, both say no leak.
- After the functionality is ended (program not exiting), the memory will slowly drops to normal level.
- Program is basically C#, WPF, C++;
So when the memory consumption gets high, the hardware (motor), which my program drives, responses pretty sluggishly.
I am very confused. Is this a memory leak?
I know it is probably hard to determine where the problem is, but is there any common logic how I should get in look at this problem? Or any commonly used tools? Like checking for intake leak/system lean on a car would be normally starting with tubes, mass air flow sensors, or O2 sensors.....
Thanks a lot!
There are a couple of things you can try -
Try running Sysinternals ProcessMonitor tool (Process Monitor v3.2) and configure the symbol path and your source code path correctly assuming you are running on windows platform. The logs will most probably tell you the line number and source which is causing the leak. You need to know how to use process monitor and navigate through the logs.
Otherwise, you can also try the below CRT API's to track memory allocation/ deallocation and spit out the memory leak dump for further investigation. The below code works only in debug mode.
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#ifdef _DEBUG
#ifndef DBG_NEW
#define DBG_NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ )
#define new DBG_NEW
#endif
#endif // _DEBUG
_CrtMemState crtMemStateStart;
_CrtMemState crtMemStateFinish;
_CrtMemCheckpoint(&crtMemStateStart);
// Your suspisious code
_CrtMemCheckpoint(&crtMemStateFinish);
int nDifference(0);
_CrtMemState crtMemStateDifference;
nDifference = _CrtMemDifference(&crtMemStateDifference, &crtMemStateStart, &crtMemStateFinish);
if(nDifference > 0)
_CrtDumpMemoryLeaks();
See this link for more information : Finding Memory Leaks Using the CRT Library
Remember always memory leaks can be a bit tricky to find especially if there is COM code involved. But having the right knowledge and tools definitely makes life a bit easier.
Memory Profiler works for me:
Memory Profiler trial version download
This the trial version, and I like it.