1

I don't use dynamic memory allocation (except for 3 lines in which i do static A* a = new... but that only happens once)...and yet when I run for several iterations memory usage as seen via top(1) seems to increase with number of iterations..I set a breakpoint with a high ignore count and then examined internal data structures to make sure they were not growing (most of my state is in a vector< vector >) but they get recycled and all entries were vectors of size/capacity 100 (the initial default) even after a while.

What are some ways in which I can investigate the growing memory trace maybe using gdb or anything else?

2 Answers 2

3

If you are on Linux, you can use the wonderful Valgrind tool. Install it, compile your program with -g flag, and run

$ valgrind ./my_prog 

And read the log it prints for you, there you will see a summary of your memory usage and instructions on how to get even more info.

Sign up to request clarification or add additional context in comments.

1 Comment

That won't spot heap fragmentation though
3

As Ivella suggest, you can use Valgrind to profile your heap (via massif) or check for memory leaks or access errors (via memcheck). You say you do no dynamic memory allocation - yet std::vector allocates on the heap via dynamic memory allocation. There is no guarantee that the C++ standard library will always return recycled heap memory back to the operating system during the run of your program - so it's entirely possible that memory utilisation might increase slowly over time whilst not leaking in any harmful way.

For memory error/leak checking:

valgrind --tool=memcheck <program to analyse> 

For heap profiling:

valgrind --tool=massif <program to analyse> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.