Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out where memory is consumed

I have this relatively large numerical application code that may run for a few days and eventually spit out some numbers. The whole thing is written in C++, making use of a bunch of 3rd-party libraries, and compiled using GCC 4.6. The code uses shared pointers throughout.

Unfortunately, over time, the memory consumption of the code increases until all of the (shared) memory is used up, then crashes. Algorithmically, the code shouldn't build up memory over time, so there'll be a bug somewhere.

I did run a small example through valgrind's leak checker which reports that all should be fine. My thought was that shared pointers might unintentionally be created someplace, preventing from unneeded data from being freed along the process (but this is just a guess).

At the end of the day, I'm running out of ideas how to debug such a thing. Any ideas?

like image 471
Nico Schlömer Avatar asked Jan 23 '26 11:01

Nico Schlömer


1 Answers

Since you already have the valgrind toolsuite available, I would advise you to run the massif tool.

Massif will track the memory allocation origins and the report will indicate you how many bytes each allocation site/function created. This will help you understand where that memory blow-up comes from.

like image 176
Matthieu M. Avatar answered Jan 25 '26 23:01

Matthieu M.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!