>From: Wu Yongwei <adah@...>
>To: mingw-users <mingw-users@...>, firstname.lastname@example.org
>Subject: [Mingw-users] Libstdc++-v3 memory leakage?
>Date: Tue, 11 Mar 2003 15:23:29 +0800
>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 ---
> vector<int> v;
>--- 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.
I had a look at mingw/include/c++/3.2.2/bits/stl_alloc.h and I am sure this
leak is harmless because STL normally allocates memory in chunks and keeps
track of freed and allocated memory itself. The only problem is that the
underlying memory isn't freed when before the program exits because it is in
static variables. However, I also found from the source that you can do
$ export GLIBCPP_FORCE_NEW=1
new: allocated 003F3CA0 (size 4, <Unknown>:0)
new: allocated 003F4CF8 (size 8, <Unknown>:0)
delete: freeing 003F3CA0 (size 4)
delete: freeing 003F4CF8 (size 8)
This environment variable causes STL to just use new & delete for all
operations which is less efficient but is useful for the type of debugging
that you are doing. Thanks for alerting other MinGW users to this issue.
>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.
Hotmail now available on Australian mobile phones. Go to