bug-gplusplus
[Top][All Lists]
Advanced

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

RE: Bug in g++ 2.96


From: lrtaylor
Subject: RE: Bug in g++ 2.96
Date: Mon, 13 Oct 2003 12:17:45 -0600

Basically, I believe that memory allocation and deallocation is a system
(i.e., kernel or C-library) function, and certain systems "optimize"
things by not releasing the memory from the process, even though you've
called free or delete.  I know that this happens on Solaris, and that
it's by design.  Given that, I would be inclined to say that this is not
a bug in GCC, but just a side effect of how the kernel or the C-library
manages a process's memory.

However, like you, I'm not an expert (I don't even play one on TV...).

Good luck,

Lyle

-----Original Message-----
From: Michael Mwangi [mailto:address@hidden 
Sent: Friday, October 10, 2003 10:26 PM
To: address@hidden
Cc: address@hidden
Subject: Bug in g++ 2.96

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]