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.
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…