Vector of shared pointers , memory problems after clearing the vector

you have two copies of shared_ptr<A> in this case, one is the sharedptr variable and the other as an element in the vector.

do this instead

test.push_back(std::move(sharedptr));

note now the original sharedptr has it’s internal moved and no longer usable. The other thing is don’t do anything at all, this is a perfectly valid usage of of shared_ptr and sharedptr will clean up itself after it goes out of scope.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)