c++ - Is it desirable to clear STL vector -


a quick question - possibly of style. desirable clear/empty vector when it's no longer required, or can rely on stl clean after when container no longer required.

i'm talking in case basic vectors don't contain pointers or other objects require delete eg.

std::vector<double> myvector; // use // finished // use clear? myvector.clear(); 

there's no benefit clearing vector, since it's not guaranteed give storage. see capacity().

if you're concerned memory used vector, can use little trick substitute empty vector:

std::vector<double>().swap(myvector); 

of course easiest method let vector go out of scope , destroyed automatically , storage freed.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -