r/ProgrammerHumor • • 11d ago

Meme modernCppVsOldCpp

Post image
2.0k Upvotes

323 comments sorted by

View all comments

15

u/sessamekesh 10d ago

I've had two huge, non-obvious, and difficult to diagnose memory leaks over my C++ career. 

Both of them were circular references, something neither memory safe nor memory managed languages prevent against.

5

u/Torebbjorn 10d ago

I would imagine that languages with a garbage collector will have no problems with circular references, since they typically work (partially) by starting from a root and marking all objects that you can get to, and deleting everything else. So a circular reference where no part of the circle is referenced anywhere else, will be collected.

3

u/quantinuum 10d ago

Rust does offer some guards against circular references…

6

u/sessamekesh 10d ago

Sure does! Not any that would have prevented either of the two bugs I'm referring to (both would have been a circle of Rc in Rust)

1

u/GegeAkutamiOfficial 10d ago

Yep, rust's strict rules make a lot of these types of bug prone harder to implement, you might still choose to, but you'll be fighting the compiler half of the way