STL-String memory leak?

Gero Krueger krueger@obk.telekom.de
Tue May 2 05:20:00 GMT 2000


Hello developers !

I've got some memory-problems using stl-strings.
I'm running RH6.1 kernel 2.2.12 with g++ 2.95.1.

Please take a look at the following short piece of code:

------------------------------------------------
#include <vector>
#include <string>

int main()
{
 vector<string *> myvec;

 for(int i=0; i<50; i++)
  myvec.push_back(new string("aaa"));

 sleep(10);

  vector<string *>::iterator eraser_it;

  eraser_it = myvec.end();      
  while(!myvec.empty())
  {
    eraser_it--;                
    if((*eraser_it) != NULL)     
      delete(*eraser_it);       
    myvec.pop_back(); 
  }
 
 sleep(10);
exit(0);
}
--------------------------------------------------

The programm should clear all memory allocated by
the "new" statement.
When I watch it with "ps axu" and take a look at its memory 
consumption - no memory is freed.

My questions are: 

Can I really measure the memory consumption with ps ?
Did I make a basic mistake ?
Or is this really a problem with the memory-handling in
the string-class ?


Thank you,
Gero Krueger

-- 
< Gero Krueger                   | DeTeCSM               >
< Tel.  : +49-541-333-2488       | IVS Osnabrueck        >
< Fax   : +49-541-333-2940       | Hannoversche Str. 6-8 >
< mailto: krueger@obk.telekom.de | 49084 Osnabrueck      >


More information about the Libstdc++ mailing list