My question concern memory management.
I got this container :
typedef hash_map<const string, Powerdomain*, strptrhash, strptrequal> PowerdomainHashMap;
now I add one element in it
PowerdomainHashMap powerdomainMap;
Powerdomain* pd1=new Powerdomain("Powerdomain1");
powerdomainMap.insert(Powerdomain_pair(pd1->getName(),pd1));
After that my program does a first step.
Now that the first step is done, i no longer need the powerdomains and want to delete them.
Is a powerdomainMap.clear() sufficient ? Will it destroy all the value entries in the map (ie call delete on every Powerdomain* in the map?
(I think it is better than calling delete on a iterator on the map but i am not sure)
No. You have manually acquired memory (using
new), you need to manually release it (usingdelete). Better to use smart pointers instead of raw pointers though (preferablystd::shared_ptr).