r/cpp • • Jan 03 '26

Are memory leaks that hard to solve?

I have been coding in cpp for the last year (not regularly) and don’t have any professional experience. Why are memory leaks so hard to solve? If we use some basic rules and practices we can avoid them completely.

  1. Use smart pointers instead of raw pointers
  2. Use RAII, Rule of 5/3/0

I might be missing something but I believe that these rules shouldn’t cause memory related issues (not talking about concurrency issues and data races)

97 Upvotes

230 comments sorted by

View all comments

Show parent comment

2

u/exus1pl Jan 03 '26

cries in C++99 ;_;

2

u/SkoomaDentist Antimodern C++, Embedded, Audio Jan 03 '26

And yet "somehow" we had a fair sized codebase that extensively used smart pointers in the early 2000s (and no, I'm not talking about auto_ptr).

Turns out the concept of "smart pointer" is a whole lot larger than just the C++ stdlib implementations.

1

u/JVApen Clever is an insult, not a compliment. - T. Winters Jan 03 '26

C++98 or C99?

3

u/exus1pl Jan 03 '26

C++98, of course I mistaken with with C99

1

u/NilacTheGrim Jan 04 '26

C++99 is not a thing. C99 or C++98.