Memory stability of a C++ application in Linux

前端 未结 6 1152
余生分开走
余生分开走 2021-01-03 05:14

I want to verify the memory stability of a C++ application I wrote and compiled for Linux. It is a network application that responds to remote clients connectings in a rate

6条回答
  •  萌比男神i
    2021-01-03 05:27

    Use valgrind to find memory leaks : valgrind ./your_application

    It will list where you allocated memory and did not free it.

    I don't think it's a linux problem, but in your application. If you monitor the memory usage with « top » you won't get very precise usages. Try using massif (a tool of valgrind) : valgrind --tool=massif ./your_application to know the real memory usage.

    As a more general rule to avoid leaks in C++ : use smart pointers instead of normal pointers. Also in many situations, you can use RAII (http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization) instead of allocating memory with "new".

提交回复
热议问题