Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

They're as "massively error-prone" as garbage-collected references in other languages.

> #1

Performance aside, unique_ptr gives you something that most languages don't have, unique ownership enforced at the language level. This makes code less error-prone. Disregarding #1 just gives you what you get everywhere else.

> #2

Basically just says, if your object isn't thread-safe, don't use it concurrently. Again, nothing specific to C++.

> #3, #4, #5, #6, #7

Well duh, don't use manual allocation or the deprecated auto_ptr in the first place.

> #8

That's the only real gotcha, and the reason why weak_ptr exists. It's the price for having RAII and destructors (because when the destructor is called, all your class members still have to be alive).

In return for keeping your pointer graph cycle-free, you get actual automatic resource management that isn't limited to memory.



Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: