Hi,
I'm using a map<string, bool> and populating it with random values to see its memory behaviour. The problem is that after every 10 thousand values, I call map.clear(). Since, string has a destructor, the memory should be freed. But the memory use of the program keeps on rocketing up. Here is the small code:
The memory use keeps on climbing up, until the program is forced to terminate by the OS. I want to be able to run this forever, is it possible?Code:int i = 0; map<string, bool> myMap; string temp = ""; while (true) { temp += i; myMap[temp] = true; i++; if (i > 5000) { cout << "Entering" << endl; myMap.clear(); i = 0; } }
What if I weren't using string but char * and allocating memory to it with the new operator?
Please reply soon if you know the answer, because I want to finish this thing in a few hours, and this is my last hope. Thanks.