I have been reading on Vectors in C++ and understand that vectors are a STL container that allow you to store pretty much anything in them. When used correctly they can be very powerful containers.

http://www.cplusplus.com/forum/articles/7459/


What I do not understand is the statement:

They provide an added benefit that they will automatically remove the memory they use when they go out of scope.

What do you mean by the statement "when they go out of scope"?

For example, considering the code below, when do we say that the 2diemnsional array (handled through a vector) goes out of scope?

Code:
#include <vector>
using std::vector;

#define HEIGHT 5
#define WIDTH 3

int main() {
  vector<vector<double> > array2D;

  // Set up sizes. (HEIGHT x WIDTH)
  array2D.resize(HEIGHT);
  for (int i = 0; i < HEIGHT; ++i)
    array2D[i].resize(WIDTH);

  // Put some values in
  array2D[1][2] = 6.0;
  array2D[3][1] = 5.5;

  return 0;
}