Freeing a List of Pointers

13 Jan, 2019 - Notes

How to free a list of pointers properly:

list<Entity*> l = ...;
while(!l.empty()){
    delete l.front();
    l.pop_front();
}

Just calling l.clear() is insufficient and will result in memory leaks.