Следующий код, скомпилированный g++ под Linux, вызывает memory leak:
void foo( string & s )
{
ostrstream oss;
oss << "Hello, world" << ends;
s = oss.str();
}
int main()
{
int i = 0; // check point 1
{
string s;
for( ; i < 10; ++i )
{
foo(s);
}
}
return( 0 ); // check point 2: memory leak?
}
Под Microsoft Visual Studio 2010 никаких проблем с этим кодом нет.
Это у меня руки кривые или где?
Здравствуйте, Аноним, Вы писали:
А>Это у меня руки кривые или где?
вам прямо так сложно доку почитать?
After any call to str(), a call to freeze(false) is required to allow the destructor to deallocate the buffer as necessary.
strstream has been deprecated since C++98, std::stringstream and boost::iostreams::array are the recommended replacements.