What are potential dangers when using boost::shared_ptr?

后端 未结 13 855
猫巷女王i
猫巷女王i 2020-12-02 07:42

What are some ways you can shoot yourself in the foot when using boost::shared_ptr? In other words, what pitfalls do I have to avoid when I use boost::shared_ptr?

13条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-02 08:30

    If you have a registry of the shared objects (a list of all active instances, for example), the objects will never be freed. Solution: as in the case of circular dependency structures (see Kaz Dragon's answer), use weak_ptr as appropriate.

提交回复
热议问题