0
votes

I've been using the various _CRTMem* functions to attempt to locate memory leaks in our code. The application is an unmanaged C++ appplication. Some strange things I've noticed:

  • There is a huge discrepance between the increase in memory use reported by Task Manager (I use its "Commit Size" metric), and that reported by using the CRT Heap Debugger functions _CrtMemCheckpoint(), _CrtMemDifference() and _CrtMemDumpStatistics(). The reported memory use increase is 200KB (Task Manager) vs 17 KB (CRT heap debugger). Can it be that windows is allocating extra memory in the background? It seems like a huge discrepancy.
  • I've been using the _CRTDBG_MAP_ALLOC #define and the function _CrtMemDumpAllObjectsSince() to get memory leak file locations. However, about 75% of the leaks don't have file location information available. Does this also indicate that extra allocations are occuring behind the scenes.

We test using Windows 7, but the final destination application will run unders Windows CE. Does WindowsCE have better (or different) memory management?

Can anyone help? Many thanks, Paul

1
Task manager reports memory that Windows has reserved for the application, not what the application actually has allocated. - Arne Mertz
The first rule here is never to use Task Manager to diagnose/debug memory leaks. - Cody Gray♦
There are many sources of commit beyond just the heap. (VirtualAlloc creates commit for example.) The CRT functions you're using count only allocated heap. Free heap is still committed. - Raymond Chen
Thanks for the replies. So I use the CRT functions to demonstrate to my colleagues how much memory is being leaked? - Paul

1 Answers

2
votes

Task Manager used to show you the real numbers, but since Vista (I think) they changed it so it would report a "simplified" report. Which is useless for serious work even if it is sufficient for non-technical users to get an idea of what's going on in their system.

Here's an article that describes some of the changes.

If you want to measure memory, use perfmon, with one of the many memory counters, or the process object's memory counters. these will give you the raw data you want.