Re: std::List doesn't releases the memory ...
<mtb455tlfqmo7r0hmqt0dap94vum2ulc8c@4ax.com>
Content-Type: text/plain; charset=ISO-8859-1
X-Original-Date: Wed, 8 Jul 2009 06:39:00 -0700 (PDT)
X-Submission-Address: c++-submit@netlab.cs.rpi.edu
On Jul 7, 3:36 am, George Neuner <gneun...@comcast.net> wrote:
On Mon, 6 Jul 2009 08:32:19 CST, RV <rahul.va...@gmail.com> wrote:
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
Is this a bug with std::List or incorrect usage of it?
The same behaviour is not observed with std::vector?
Does anyone knows the solution for this?
Thanks and With Warm Regards,
-RV
Please don't post code with tab characters in it.
How exactly are you measuring memory usage? If you are trying to use
"ps" then you should know that, in normal use the process heap will
only ever expand ... it will never shrink without the program making
an explicit call to brk() or sbrk().
I'm not sure why you see different behavior with std::list and
std::vector. std::list.clear() is supposed to release the list's
memory - you could see leakage from object elements in the list, but
with integer elements that can't happen and you'd see the same leak
from a vector.
I am using top command for the memory reading.
Get yourself a profiling tool such as valgrind (http://valgrind.org/)
and see what it says about your program.
I used valgrind but its not showing the leak. The memory is not being
released even if the destructor of std::list is being called. So if
before std::list object is being created if memory reading from
program is N then after destroying the std::list object, I am
expecting the memory reading to be same i.e. N
George
Thanks and With Warm Regards,
-RV
--
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]