This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Leakage from initialization of pair<..., string>
- From: Wu Yongwei <adah at netstd dot com>
- To: libstdc++ at gcc dot gnu dot org
- Date: 07 Jul 2004 19:48:40 +0800
- Subject: Leakage from initialization of pair<..., string>
This message was first posted to gcc list, with no response. Maybe it
could have better luck here?
Tracing the memory allocation/deallocation of the following short
program shows a problem:
------------------------------------------------------------
#include <memory>
#include <string>
typedef std::pair<unsigned, std::string> uint_str_t;
std::pair<unsigned, std::string> g_key_id_name_pairs[] = {
uint_str_t(64, "@"),
uint_str_t(65, "A"),
uint_str_t(66, "B")
};
int main()
{
}
------------------------------------------------------------
Three times operator new(14) are called, with no operator delete called
(when GLIBCPP_FORCE_NEW=1). This problem is confirmed to exist on (at
least) MinGW GCC 3.3.1, MinGW GCC 3.4, and Linux GCC 3.2.3. This problem
does not exist on GCC 2.95.3.
Using real struct in place of pair will not cause the leak. Using a
simplistic user-defined string implementation will not, either. I am
guessing it is from some specific implementation of string (maybe
reference counting?). I did not trace it out (as an end user I am unable
to trace into string; I have not much experience in building gcc
myself).
Anyone with clues?
Best regards,
WU Yongwei