From: Bastien C. <ba...@ch...> - 2003-04-26 09:41:47
|
On Saturday 26 April 2003 02:03, Lee, HJ wrote: > If I use string type for example ---> string a("Hello, world"), the memory > allocated for string isn't freed when program exit. > valgrand reported it is not-freed block. Here is valgrind reports logs. > Why is it not freed when program exits? I am using RH6.2. The thread ""Reachable" memory, where's the bug (g++, STL, valgrind)?" might help you there. In short: the C++ STL and string function have their own memory pooling mechanisms to gain speed. The memory of these objects is not 'freed' per se when they are destructed, but returned to the internal memory pool and will be reused for other objects created. It's these pool fragments (which are not freed by the C++ library before exit) that valgrind chokes on. While you can minimise this behaviour with the STL by providing your own allocators (not recommended, slows down execution speed terribly on some systems), I am not aware of similar mechanisms for the string classes. Salut, Bastien PS: This is _definitively_ something for the FAQ. -- -- The universe has its own cure for stupidity. -- -- Unfortunately, it doesn't always apply it. -- |