When you store raw pointers to dynamically allocated objects in containers, containers will not manage their memory.
vector<FooBar*> vec; vec.push_back(new FooBar);
To make it more secure for data storage, use smart pointer containers or special-purpose pointer containers, as in Boost: pointer containers
In particular, given that if an exception is thrown, execution may not reach the manual cleanup code (unless painful efforts are made).
source share