This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

list class free memory problem


Hi,

I am now using the following tools to build an simple application using C++ STL Container (list).

OS: Linux Redhat 7.3
Compiler: GCC 3.2.1
Library: libstdc++-v3 (the default one in GCC 3.2.1)

The code of the application is:

#include <iostream>
#include <list>

int main(int argc, char* argc[])
{
    wcout<<L"===== Press any key to start ====="<<endl;
    wchar_t ch;
    win>>ch;

    // build a list to contain 100,000 double integers
    wcout<<L"Build a list to contain 100,000 double integers"<<endl;
    list<double> clList;
    double d=1.0;
    for (long i=0; i<100000; i++)
    {
        clList.push_back(d);
        d++;
    }
    
    wcout<<L"===== Press any key to continue ====="<<endl;
    wcin>>ch;
    wcout<<L"Clear the list"<<endl;
    clList.clear();

    wcout<<L"===== Press any key to end ====="<<endl;
    wcin>>ch;

    return 1;
}

I used the G++ compiler to generate the EXE file.
Then, I ran the EXE file and use 'top' command to check the memory usage of the application.
After I pressed any key to start building the list, the memory usage was increased. (normal and expected !!!).
After clear the list and before I pressed any key to end the application, I found that the memory usage did not reduce (not expected !!!). Until the application exited, the used memory was freed.

When I modified the application to build one more list (2 lists) and clear each lists after building them, the memory usage increased more and did not reduce after clear all the lists.

Actually, I needed to use this library to build many lists to temporary store data in my application. But, I found that the memory usage increased very fast and I cannot free the used memory through all the function called provided by STL Container class. (e.g list::clear(), list::erase(), list::pop_back(), list::pop_front, etc).

I tried many methods but still cannot free the memory used by the list when the application is running.

Would you mind to tell me how to do this?

Also, I found that this problem does not appear in Microsoft Windows (Visual C++ 6.0).

Kathy


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]