Suppose I have VectorA and VectorB are two std::vector<SameType>, both initilized (i mean VectorA.size() > 0 and VectorB.size() > 0)
If I do:
VectorA = VectorB;
the memory previosly allocated for VectorA is automatically freed?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It is freed in the sense that the destructors of all contained objects are called, and the vector no longer owns the memory.1
But really, it’s just returned to the allocator, which may or may not actually return it to the OS.
So long as there isn’t a bug in the allocator being used, you haven’t created a memory leak, if that’s what your concern is.
1. As @David points out in the comment below, the memory isn’t necessarily deallocated, depending on whether the size needs to change or not.