This is a common source of misunderstanding: a programmer creates a container of pointers, then fills that container with pointers to dynamically allocated objects. When the container is destroyed, the programmer mistakenly assumes that the objects are deleted. However, they aren’t because the container contains pointers, not real objects. Consider:
v;v.push_back(new Derived);v.clear(); // doesn't delete the object!
To properly destroy the objects of a container of pointers, you should explicitly delete its pointers before destroying the container itself:
v.push_back(new Derived);// delete the object whose pointer is stored in vdelete v; // now clear the containerv.clear();