Diagnosing Memory usage under C++

T

Tommy Vercetti

I have a large (~100K lines) C++ server application that exhibits memory
problems: after about 6 hours of high volume use, it can reach RAM
levels of 1.3GB which is unacceptable.

Most leak detection or C++ memory profiling tools are targeted at the
really blatant traditional C/C++ leaks where a certain piece of
frequently used code calls new/malloc and has no matching delete/free.

My application really isn't this simple. The bulk of my app's RAM use is
through Boost smart pointers, STL collections, and STL strings. I see
excellent profiling tools for Java/C# such as JProbe which help diagnose
such complex memory use issues but I really don't see a parallel for C++.

I've tried the leak detection system built into VC++, Purify, and a few
other tools but none of them prove fruitful.

I've manually reviewed any use of new/malloc and everything looks OK.
I'm more inclined to suspect that a data cache has grown too large, or
there is just too much of a certain kind of data in RAM. Basically, the
kind of "leaks" that are also present in Java/C# development and not the
simple C/C++ style memory leak.

Any ideas/suggestions? Would getting a Microsoft Managed C++ build of my
application help anything? A complete transition to C#/Java is obviously
way too involved at this point and is out of the question.

thanks!
 
S

Steve Waggoner

My application really isn't this simple. The bulk of my app's RAM use is
through Boost smart pointers, STL collections, and STL strings. I see
excellent profiling tools for Java/C# such as JProbe which help diagnose
such complex memory use issues but I really don't see a parallel for C++.
I've manually reviewed any use of new/malloc and everything looks OK.
I'm more inclined to suspect that a data cache has grown too large, or
there is just too much of a certain kind of data in RAM. Basically, the
kind of "leaks" that are also present in Java/C# development and not the
simple C/C++ style memory leak.

Any ideas/suggestions? Would getting a Microsoft Managed C++ build of my
application help anything? A complete transition to C#/Java is obviously
way too involved at this point and is out of the question.

I would see if it truely a memory leak. It might be you either fragmented
the
memory with too many small allocations or you have stl containers that have
memory still reserved.

What I did to figure this out was put all variables in one structure. See
how much
memory is used when you start the program. After 6 hours usage. Delete the
structure and reallocate it and see if your memory usage is back to normal.

If the case is too many small allocations then you have to rethink your
design.
If the case is the stl containers are hording memory look at page 77 of the
"Effective STL" book about freeing excess container capacity.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top