weak_ptr 共 1 篇文章

C++智能指针std::shared_ptr的循环引用解决方案
2026-04-02 19:19:15
C++智能指针std::sharedptr的循环引用解决方案 C++标准库中的std::sharedptr通过引用计数自动管理动态内存,但当两个或多个对象互相持有对方的sharedptr时,会形成循环引用,导致引用计数永远不会归零,从而引发内存泄漏。解决这一问题的核心方法是使用std::weakpt
C++智能指针 shared_ptr weak_ptr
9 0