The best alternative to freeing pointers using delete , or using something that abstracts them (like smart pointers or pointer containers), is to simply create objects directly on the stack.
You should prefer test t; over test * t = new test(); You very rarely want to deal with any pointer that owns a resource, smart or otherwise.
If you used std::list "real" elements, rather than pointers to elements, you would not have this problem.
source share