Re: Desctruction of objects inside a static nested map holding
On Nov 23, 3:04 pm, alan <almkg...@gmail.com> wrote:
On Nov 23, 9:55 pm, jayaramganapa...@gmail.com wrote:> Hello friends,
I have a map like std::map< std::string , std::map<std::string,
std::string>* > EpPropCache::propertyCache ; (This is a static
instance and taken from *.cpp file)
As you can see the value is a pointer to another map. I do new of
std::map<std::string, std::string> and add the pointer to the map.
Do I have to delete the map objects which I create with new , which I
store on the static map instance?
Alternatively, use boost::shared_ptr<std::map<std::string,
std::string> >, which will automatically release them.
Or even better, perhaps, just skip the pointer. There's nothing
that says a map cannot contain maps. Something like:
std::map< std::string, std::map< std::string, std::string > >
Just make sure that, except for initializing a shared_ptr (and
initializing only from a new), you do not, ever, assign a
shared_ptr from a plain old pointer. shared_ptr to shared_ptr
is what you should always do.
Except when it might lead to a cycle. (Not a risk in this case,
Or Will the destructor of the map be called when the program
exists? In that case I should be able to see log messages.
Yes, if it exits. If it sits running for a long time instead,
If the object is static, he probably doesn't want the destructor
to be called before program exit. (Or if he wants the
destructor called before program exit, he shouldn't declare the
James Kanze (GABI Software) email:firstname.lastname@example.org
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34