C++ Smart Pointers

The cluster debates the safety, performance, and idiomatic use of smart pointers like shared_ptr and unique_ptr versus raw pointers in modern C++, including RAII, memory management risks, and whether they fully solve correctness issues.

➡️ Stable 0.6x Programming Languages
5,229
Comments
20
Years Active
5
Top Authors
#9849
Topic ID

Activity Over Time

2007
2
2008
7
2009
22
2010
32
2011
84
2012
140
2013
163
2014
273
2015
262
2016
361
2017
343
2018
279
2019
358
2020
445
2021
431
2022
537
2023
454
2024
441
2025
448
2026
149

Keywords

AFAIK UB ideone.com github.io RAII cppreference.com RxCpp SFINAE NULL www.gotw pointers std pointer gadget exception const foo raw raii assignment

Sample Comments

lupire Oct 18, 2022 View on HN

What are the main correctness risks in C++ if you just never use a raw pointer?

ndesaulniers Mar 31, 2017 View on HN

"folks it's ok, we're using shared_ptr's. We're safe. Problem solved."

thwest Feb 27, 2013 View on HN

How is a C implementation of std::shared_ptr safer?

a_t48 Jan 16, 2020 View on HN

Can you give an example of unique_ptr being too heavy?

StilesCrisis Sep 1, 2025 View on HN

If you think the problem with C++ is that shared_ptr exists, you should probably just use C.

shmerl Jun 5, 2015 View on HN

Doesn't using C++ RAII eliminate some of that? Or you use raw pointers often?

barrkel Apr 22, 2011 View on HN

Unless you modified an existing or wrote a new C++ compiler, no, you haven't really (don't forget what you're piggy-backing on when the compiler is invoking ctors and dtors for you too). Boost shared pointers are toys; they don't deal with copy-on-write semantics. C++ exception safety is also hilariously difficult to get right (this adds to the refcounting problem); the language is broken by design.

tomjen3 Dec 15, 2021 View on HN

Javascript isn't to blame: bad C++ is. It is 2021 and if you are not putting things in smart pointers, you are doing it wrong.

eptcyka Nov 15, 2025 View on HN

What would be the detrimental effect of using smart pointers?

VHRanger Nov 2, 2022 View on HN

If only unique_ptr makes the whole experience so much better