RV <rahul.va...@gmail.com> writes: > Hi, > > I have compiled the following source code on SuSE linux with g++ > compiler version 3.4.3. > > #include <iostream> > #include <list> > > void PopulateList(std::list<int> & li, int numitr) > { > for(int i = 0; i < numitr; i++){ > li.push_back(i); > } > } > > void testList() > { > char ch; > int numitr; > > std::list<int> li; > std::cout << "Enter any charater to continue : Before > Populating std::list<int> : take memory reading: "; > std::cin >> ch; > std::cout << "How many iteration: "; > std::cin >> numitr; > > PopulateList(li, numitr); > > std::cout << "Press any charater to continue : After > Populating std::list<int> : take memory reading: "; > std::cin >> ch; > > li.clear(); > > std::cout << "Press any character to continue : After > clearing std::list<int> : take memory reading: "; > std::cin >> ch; > } > > int main() > { > while(1) { > testList(); > std::cout << "==>\n"; > std::cout << "==> End of while\n"; > std::cout << "==>\n"; > } // End of While > } > > OBSERVATION: > > The multiple iteration of while loop doesn't release the memory > occupied by the std::list
Yes it does. The memory is freed. If you try to allocate the list again, you will see that no more memory is asked from the OS. What you are observing is not the occupied / free memory in the process memory space, but the size of the process memory space allocated to the process by the OS. The OS doesn't lose its time, and more importantly, doesn't make the OS and all the other lose their time, in returning the memory to the OS, while the application is still running and may still need that memory. > Is this a bug with std::List or incorrect usage of it? No. > The same behaviour is not observed with std::vector? Yes. > Does anyone knows the solution for this? This is not a problem you want to solve. -- __Pascal Bourguignon__ _______________________________________________ help-gplusplus mailing list help-gplusplus@gnu.org http://lists.gnu.org/mailman/listinfo/help-gplusplus