`std::shared_ptr`: Seamless C++/Python Shared Ownership

Pybind11 natively supports `std::shared_ptr` as a holder type for C++ objects, enabling seamless shared ownership and correct reference counting between C++ and Python. This prevents common memory errors like double-frees and ensures proper object lifetime management across language boundaries.

Sources

Open the full topic