There's a bunch of myths about why C++ (and C) are "dangerous" and those myths often revolve around pointers and memory leaks. But bugs related to pointers and memory leaks are in fact just beginner-level problems one writes while still learning the language.
These are not major concerns unless you have an organization with a lot staff throughput and repeatedly hire junior programmers for work which is more qualified than they are ready for... which is no fault of any given programming language.
Now there is indeed a ridiculous stupid flaw in the C++ language - namely that Stroustrup made new
and new[]
two different operators. This is a language design mistake constantly leading to memory leaks and the problem is that the programmer used delete
rather than delete[]
and that passed compilation silently. This should have been fixed 40 years ago, instead of making up stupid coding practices like "do not handle dynamic allocation manually".
On the other hand, C++ has gone to extreme lengths dealing with memory leaks by including smart pointer classes in the standard library, something that has been refined through several iterations of the language standard.
But in general, memory leaks never was a big problem among experienced programmers. You clean up your own mess and there's destructors for that. What's the problem.
Well... one big problem would be to introduce a performance-heavy dead weight thread representing your mom, going up and cleaning up the mess you've made, because you are too irresponsible to even understand how to do so yourself. Why would I force that thread into my program when I'm an adult quite capable of cleaning up my own mess? I don't need a garbage collector because I have no habit of leaving garbage behind. Besides that, bugs should be fixed, not swept underneath the carpet. Garbage collection is ridiculous nonsense.
Also modern compilers got dynamic analysis which can find memory leaks easily enough. Before that there were stand-alone dynamic analyzers like Valgrid. If you don't use static as well as dynamic analysis of your code, well that's a quality problem in your software workflow not really related to any given programming language. There are no perfect programming languages, you always need a quality system which includes testing, or you'll produce bugs no matter language.
I wrote a little article about the problems of dynamic allocation in embedded systems here: Why should I not use dynamic memory allocation in embedded systems? Among the many problems mentioned, some are far greater concerns even in generic or hosted system C++ programming: particularly the execution overhead and user data fragmentation problems. These are genuine real-world performance problems and in higher level languages than C++, you don't even get to solve these problems: they are built-in with the picked language.
As for safety concerns of C++, they are of an entirely different nature not the slightest related to pointers and dynamic allocation! The main problem with C++ is feature bloat, complexity and the countless forms of poorly-defined behavior that comes from it. No living person even knows of all forms of pooly-defined behavior existing in the C++ language. Now that is a legitimate reason to avoid C++ like the plague. If you are to avoid a language, make sure to do so for the right reasons.