[C++] clearing a map?

on to my next c++ issue…
I cant seem to get rid of a memory leak when using a map.
I tried this code i found on the net which is supposed to solve the problem but even this isnt working.


int main()
{
	std::map<int, char*> Mappy;
	
	for(int Index = 0; Index < 1024*1024; ++Index)
		Mappy.insert(std::make_pair(Index, new char[10]));

	for(std::map<int, char*>::iterator MapItor = Mappy.begin(); MapItor != Mappy.end(); ++MapItor)
	{
		char* Value = (*MapItor).second;
		delete Value;
	}
	cout << "tömd: ";
	cin.get();
	return 0;
}

According to top that program eats like 5,7 mbs of RAM… running that without inserting all that data into the map it eats something like 0,3 mb i think.

any help appreciated…

This is an old thread I know, but just in case someone comes across this like I did.

for(std::map&lt;int, char*&gt;::iterator MapItor = Mappy.begin(); MapItor != Mappy.end(); ++MapItor)
{
    char* Value = (*MapItor).second;
    delete Value;
}

You are clearing the memory correctly but you aren’t erasing the now invalid pointer from the map.
after this loop call something like:

Mappy.clear();

You should see a decrease in the memory used once there aren’t like 1,000,000 invalid pointers in memory.
Although I’m sure you figured this out by now…

Happiness takes no account of time.    / ./ /_   I Hand You  {^_ }  ) }/^&#12288;   A Rose… / /_/^.}/ // / ( ({(@)}_}.///A___Awow gold____A__[url=http://www.comegames.com/gamecy.jsp]wow goldA______A___ _/{/()_} )\ \—v----V-----V–Y----v—Y-----  (  (__))/ )\ &gt;     _/   _///