If there are pointers in your containers, the destructor for these objects will not be called (the STL will not follow these pointers and will call the destination destructor).
, , .
. . , ( delete). .
#include <map>
#include <string>
#include <iostream>
using namespace std;
struct myObj{
~myObj() {
cout << "DESTRUCTION" << endl;
}
string pkid;
string data;
};
map<string,myObj*> container1;
map<string,myObj*> container2;
int main()
{
myObj * object = new myObj();
object->pkid="12345";
object->data="someData";
container1.insert(pair<string,myObj*>(object->pkid,object));
container2.insert(pair<string,myObj*>(object->pkid,object));
container1.erase(object->pkid);
container2.erase(object->pkid);
delete object;
}