How to free memory in case of map

I wanted to the know how to delete or free memory in case of map and other stl containers.
Recently while going through a problem i founded that map.clear() doesnt free up the memory but it only removes the element and these memory locations may get filled with garbage values.
so if anybody knows how to free up memory in map and other stl containers please tell.
i also read about smart pointer but couldn’t understand it. @ssjgz ,@galencolin , @akshitm16 or anybody who has any knowledge about it please tell

It automatically gets deleted once the function execution is over, you can’t delete the memory that you didn’t assign with ‘new’ keyword because its out of your control.

Maybe this would help.

thanks but it doesnt really help,suppose i made a mapof<ll,vector>(here ll =long long).lets suppose mp[1] holds(x elements) which i want to pass to mp[2].
so here i wanted that memory allocated to mp[1] gets completely deleted,which i am unable to do as mp[1].clear() doesnt does that, it only removes the element and not free ups the memory and delete also doesnt work(or i am unable to do it ).moreover i even dont know whether this could be done,but there may be (like smart pointers which i dont know) some way to do it.

I do not know about this but I must say if you need to change the container from 1 key to another key in a map then maybe this is the wrong data structure you are using. If someone else can help then it would be great.