Vector of shared pointers , memory problems after clearing the vector

后端 未结 4 1586
暗喜
暗喜 2021-01-31 03:21

I realized that after calling vector.clear() which hold shared pointers, the destructors of the object which own by shared_ptr is not being released. <

4条回答
  •  旧时难觅i
    2021-01-31 03:59

    Here sharedptr and the element in vector share the same object which will result in invoking constructor and destructor only once.

提交回复
热议问题