This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Libstdc++-v3 memory leakage?


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);
> 	v.push_back(1);
> 	v.push_back(2);
> }
> ---  end test.cpp  ---
[snip]
> I never posted to libstdc++, and apologize for any ignorances.  I 
> searched for leakage in the list but did not find any relevant infomation.

Hi,

The threads beginning with these messages might be relevant:
http://gcc.gnu.org/ml/libstdc++/2002-10/msg00038.html
http://gcc.gnu.org/ml/libstdc++/2002-11/msg00177.html

(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:

int main()
{
	for (int i = 0; i < 1000; ++i)
	{
		vector<int> v;
		v.push_back(1);
		v.push_back(2);
	}
}

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,

jon

-- 
"For a successful technology, reality must take precedence over public
 relations, for Nature cannot be fooled."
	- Richard P. Feynman


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]