Possible Duplicate:
How to release std::vector if there is no heap memory
c++ noob here
Suppose I declare a vector of vectors like:
vector<vector<vector<double> > > phi_x;
After I'm done using it, how do I destroy it to free up memory?
I've read some other sites and they recommend using .clear(). From my understanding, this only deletes the elements but the vector capacity is not released. I want the vector to be completely forgotten like it never existed.
Also, my current application of the vector has dimensions of 54x54x9 and I've got about 12 of these things. Is that considered stupidly big?
The C++ function std::vector::clear() destroys the vector by removing all elements from the vector and sets size of vector to zero.
Yes. vector::erase destroys the removed object, which involves calling its destructor.
Yes. For each time a new[] expression is executed, there must be exactly one delete[] .
You don't have to do anything. Just let the variable go out of scope.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With