3 ms·
You should look into modern c++ - at least C++11. While it is possible to write the code with all the problems you state, C++11 adds some neat features that me
by bluGill 6y ago
You should look into modern c++ - at least C++11. While it is possible to write the code with all the problems you state, C++11 adds some neat features that mean in practice you rarely do. Sure I can put something on the heap and forget to free it - but in practice I don't put anything on the heap without first wrapping it in something on the stack so that when the thing on the stack goes away my thing on the heap does too. This can get really complex fast to deal with edge cases, but most of the time the complexity is hidden and so doing the right thing that always works is just as easy as putting something on the heap that I have to remember to free latter.
Most people use address sanitizer not valgrind for the few times they have a memory leak. In general though the problem is solved not by tools but by using the modern C++ features. Valgrind is really only useful when you need to deal with C interfaces. (note interfaces, the code on either side need not be written C)