I need to free (to avoid memory leaks) the all allocated memory for following C++ code(std::map
, both key & value created by using new
).
int main()
{
std::map<char*, char*> *mp = new std::map<char*, char*>;
char *a = new char;
a = (char*)"abc";
char *b = new char;
b = (char*)"pqr";
mp->insert(std::pair<char*, char*>(a, b));
a = NULL , b = NULL; // no extra pointers to keys now //
printf("element : %s", (*mp)["abc"]); // working
// need to free the allocated memory by the map in here properly,
// clear() & erase() are ok? Because I think, I need some 'delete's
}