gnu.g++.help
[Top] [All Lists]

std::List doesn't releases the memory ...

Subject: std::List doesn't releases the memory ...
From: RV
Date: Sun, 5 Jul 2009 23:19:51 -0700 PDT
Newsgroups: gnu.g++.help

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

<Prev in Thread] Current Thread [Next in Thread>