What is the difference between std::unique_ptr, std::shared_ptr, and std::weak_ptr?
Last updated
unique_ptris sole ownership: move-only, pointer-sized, zero overhead, and the default choice.shared_ptris shared ownership via a control block with an atomic strong count. The object dies when the last owner releases.weak_ptrobserves ashared_ptrwithout keeping it alive. Uselock()to access it, ideal for back-references, caches, and breaking cycles.