I encountered some memory leakage using "gcc version 3.2.2 (mingw
special 20030208-1)", and I reduced it to the following simple test case:
--- begin test.cpp ---
--- end test.cpp ---
debug_new.cpp and debug_new.h are my simple leakage detector. They are
not directly related to this problem. One may use any leakage detector,
I suppose. For the ease of reproducing the problem, I attached them
here. The command line I use is simply "g++ test.cpp debug_new.cpp".
One point to notice is that if I uncomment the "reserve" line, the leak
is gone. If I change 33 to 32, the leak comes back.
I know that not all kind of memory leakage will cause problems, but 1) I
need to be assured of the harmlessness; and 2) the leakage report
defeats my purpose to easily catch my own memory leaks, because it is
hard to tell which is caused by which.
This problem does not seem to exist in the libstdc++ w/ GCC 2.95.3, nor
in SGI STL or STLport.
I never posted to libstdc++, and apologize for any ignorances. I
searched for leakage in the list but did not find any relevant infomation.
From: Jonathan Wakely <cow@co...> - 2003-03-11 11:08:39
On Tue, Mar 11, 2003 at 03:23:29PM +0800, Wu Yongwei wrote:
> I encountered some memory leakage using "gcc version 3.2.2 (mingw
> special 20030208-1)", and I reduced it to the following simple test case:
> --- begin test.cpp ---
> #include <vector>
> #include "debug_new.h"
> using std::vector;
> int main()
> vector<int> v;
> // v.reserve(33);
> --- end test.cpp ---
> I never posted to libstdc++, and apologize for any ignorances. I
> searched for leakage in the list but did not find any relevant infomation.
The threads beginning with these messages might be relevant:
(libstdc++ people, this is being reported fairly frequently, shall I add
it to the "things that look like bugs but aren't" section of the docs?)
If you change your test program as follows:
for (int i = 0; i < 1000; ++i)
then you'll see that the memory "leaked" is constant for any number of
std::vector<int> instantiations. The memory is held in a cache that
libstdc++ re-uses. As explained in the responses to the messages given
above, this is not considered a leak since the memory is always
reachable by the library and is never lost. I think this is what your
debug code is reporting as a leak.
hope that helps,
"For a successful technology, reality must take precedence over public
relations, for Nature cannot be fooled."
- Richard P. Feynman