How to release std::vector if there is no heap memory

前端 未结 3 817
不知归路
不知归路 2021-01-18 05:13

I have a class member variable like this:

vector >  m_stacks;

When I populate it, I do like this:

v         


        
3条回答
  •  借酒劲吻你
    2021-01-18 06:16

    The destructor for a vector will do two things: it will destroy each element of the vector, then it will free the memory used for the vector itself. This is automatic.

    In your case you have vectors nested two deep, but it doesn't matter. When the top level vector is destroyed it will call the destructor for each vector it contains, and all of those vectors will clean themselves up properly.

提交回复
热议问题