bug-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bug in g++ 2.96


From: Michael Mwangi
Subject: Bug in g++ 2.96
Date: Sat, 11 Oct 2003 00:26:29 -0400 (EDT)

Hi:


Before I begin, I must first make the following disclaimer: Although I have 
considerable programming experience, I do not consider myself by any means 
to be an expert C++ programmer. The following may be nothing more than a 
relection of my ignorance. If what I describe is not an actual bug, I would 
be very appreciative if you could briefly explain to me how I can de-allocate 
memory allocated by a set class, since everything I have tried is in vain 
and every computer scientist I have asked seems as dumbfounded as I.


I am running g++ 2.96 on a i386 redhat linux platform. I think I discovered 
a bug. I compiled and ran the following program.  

#include <set>

int main()
{
     unsigned long j;
     set<unsigned long> *o = new set<unsigned long>();
     for(j = 1; j <= 1000000; j++)
     {
         (*o).insert(j);
     } 
     (*o).clear();
     delete o;
     while(1);
}

Using top, I monitored memory usage and noticed the delete operation did 
not free the 24 MB allocated by the multiple calls to insert in the for 
loop. This problem seems confined to the set and map classes. No matter 
what I seem to do, I cannot de-allocate memory allocated by the set or map
classes. I do not enounter the problem with the vector class. For example, 
I did not observe using top any memory leakage when I compiled and ran 

#include <vector>

int main()
{
     unsigned long j;
     vector<unsigned long> *o = new vector<unsigned long>();
     for(j = 1; j <= 10000000; j++)
     {
         (*o).push_back(j);
     } 
     (*o).clear();
     delete o;
     while(1);
}

I know that clear alone at least for a vector does not de-allocate memory 
since it merely erases the elements without altering the capacity. 
Nevertheless, shouldn't the delete operation, whether it is applied to 
an empty vector, set, or map, always perform the necessary de-allocation?


Michael Mwangi






reply via email to

[Prev in Thread] Current Thread [Next in Thread]