If this is a linux environment, using gnu gcc, then Valgrind is an excellent free memory profiling tool.
Main Topics
Browse All TopicsHi,
I need to measure the size of allocated memory by my C++ application to be sure there is no more memory leakage. Is it possible by Window's Task Manager or by any other tool? What column should I watch?
My OS is Windows XP.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
>> My OS is Windows XP.
DOH! My bad.
The memory shown in the task manager, is the total amount of memory that the OS has assigned to your application. You can use this, to observe when you application frees memory, and when it mallocs memory, but it cannot tell you much else. If you have an application that dynamically mallocs/frees alot, it can be hard to detect small memory leaks, as the memory bounces up and down.
If your application is rather static in how it allocates memory, you may be able to observe a steady growth of allocated memory that _may_ indicate a memory leak.
You are much better off using developer tools and memory profiler tools to actually observe and find memory leaks though.
I have created a test - allocate few MBs. Mem Usage was not changed, while VM Size was incremented. After delete the allocated memory the VM Size decremented to the previous value. So it seems the VM size is what I am looking for, I just wanted to be sure it is reliable.
To detect memory leaks I am using overloaded operators new and delete, it works. My code is probably ok, but I am using some libraries and my application is running as a dll plugin inside another one, so it is a little bit complicated...
Well, I know that personally, I would not trust the Task Manager for something as critical as memory leak verification. Reliable, probably. How to interpret what you see? That is more difficult.
If you have overloaded new and delete, and are doing your own memory tallying, then I wold trust that more than I would trust the task manager. As you said, your application is run in a special way. How can you then use the task manager? If you suspect a memory leak from looking at the task manager, it may not even be in your code, it may be in the libraries you use.
Why don't you use some form of statistics in your own code, for the new and delete, and then your code can report any outstanding allocated memory at exit. This would be much more reliable than the task manager. Doing that, and also using some developer tools, would be a lot more reliable and efficient than using the task manager.
The simplest way to check if your code is leaking without resorting to memory profiling is just to enable the CRT (C Runtime) memory debug tools. Then, when you run your application you'll get a report of what, if any, memory leaks were detected. You can then set break-points on the allocations to see where the leak starts from.
You can use _CrtSetDbgFlag to enable CRT heap allocation debugging. This should be at the very start of your program.
E.g. _CrtSetDbgFlag ( _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG ) | _CRTDBG_LEAK_CHECK_DF );
http://msdn2.microsoft.com
You can use _CrtDumpMemoryLeaks to generate an error report if the application failed to free all the memory it allocated. This should be at the very end of your program.
http://msdn2.microsoft.com
Use can use _CrtSetBreakAlloc or _crtBreakAlloc to set break points where specific heap is allocated (as reported by CrtDumpMemoryLeaks) so that you can see where the problem starts
http://support.microsoft.c
Memory leak detection and isolation: http://msdn2.microsoft.com
The memory usage shown my Task Manager is not accurate (I had a link to a great article but right now I can't find it but if I do I'll be sure to post it for you). If you just want to monitor memory usage then consider using Perfmon, which is a tool that comes with Windows for monitor performance, including memory usage, of a process. You probably want to watch private bytes.
http://technet.microsoft.c
http://msdn.microsoft.com/
Alternatively, the excellent Process Explorer can be used to perform quick memory usage checked.
http://technet.microsoft.c
Business Accounts
Answer for Membership
by: Infinity08Posted on 2009-04-14 at 01:22:09ID: 24135872
>> Is it possible by Window's Task Manager
Sure, if you just want to see if the memory usage keeps increasin, when it shouldn't, you can use the task manager. Just check on the Processes tab, in the Mem Usage column (you might have to enable the column using View > Select Columns).
Alternatively, if what you need is a more in-depth analysis of the memory usage, with tools to help you find memory leaks, then consider using a proper memory debugger, like Insure++, or Purify, or ...