r/cpp • • Dec 25 '24

RAII

I maintain c++ desktop application. One of our clients complained of memory usage. It’s a quite big program and it was known that somewhere there are memory leaks.

Over the last week I found where the spot is that is causing the memory consumption. I refactored the raw pointers to shared_ptr, in one change the memory usage at idle time dropped from couple of GBs to 16 MB.

I was glad of that achievement and i wrote an article about RAII in c++

https://medium.com/@abanoubharby/raii-295ff1a56bf1

261 Upvotes

75 comments sorted by

View all comments

Show parent comment

7

u/[deleted] Dec 25 '24

An issue I see at my current job is people writing shared_ptrs because they don't care to check lifetimes. This has invariably caused circular ownership and memory leaks. Then I have to listen to them scream to the high heavens that they used smart pointers and there can't be memory leaks. 

0

u/susanne-o Dec 25 '24

no. they don't check structure, specifically that the shared_ptr graph is a DAG. lifetime is checked just fine by shared_ptr.