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

前端 未结 3 821
不知归路
不知归路 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:18

    The std::vector destructor calls a delete on the memory it allocates, thereby calling that types (in this instance, a std::vector's) destructor.

    These data structures all rely on SBRM (Scope bound resource management), or RAII (Resource acquisition is initialisation) principles, in that all memory they allocate is de-allocated once they go out of scope (such as the scope of a class).

    You do not need to worry about the releasing of memory from a std::vector unless it holds a type which points to memory; but does not release it inherently (such as a pointer!).

提交回复
热议问题