memory leak unit test c++

后端 未结 6 1258
天涯浪人
天涯浪人 2021-01-05 18:15

I have just resolved a memory leak in my application and now I want to write a unit test to ensure that this does not happen again.

I\'m look for a way to detect th

6条回答
  •  误落风尘
    2021-01-05 18:50

    You can also use google test framework (gtest) and then use google performance tools (gperf) to find leaks. GPerf puts in a replacement memory library and if there is a memory leak found after the test run completes it will let you know and gives you a pprof command to run with several different output formats - text, dot, web, etc. This tool will find leaks in both tests and production code.

    I also use Valgrind to confirm if there is a leak when questionable but prefer gperf. One gotcha is that if you have compiled with the gperf memory library and try to use Valgrind, it won't find any issues because it catches the leaks so you need to clean compile between switching or have a second copy of the project.

提交回复
热议问题