Hello I would like to ask about:
I have map and list
Questions:
Is the following implementation of distructor right :
for (map<string,SymbolTableNode*>::iterator i = symbolTable.begin();
i != symbolTable.end(); ++i)
{
delete i;
}
symbolTable.clear();
or I miss some memory?
About list:
list<MyClass2*> mylist;
mylist.push_front(new MyClass());
mylist.pop_front();
does pop invoke delete? or I have memory leakage in this case? If there is the leakage problem then what can I do to avoid it?
Thank you.
Do you really need to have a list of pointers ? Can’t you have a plain list ?
It will save you the pain of memory management.
If you need pointers, then use smart pointers or pointer containers from boost : http://www.boost.org/doc/libs/1_46_1/libs/ptr_container/doc/ptr_container.html