Original Post
I've encountered some strange behaviour from STLport's std::string implementation. Consider the following code (run through debugger):
#include <crtdbg.h>
#include <string>
void DoStuff() {
std::string S("foobar");
}
int main() {
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF|_CRTDBG_LEAK_CHECK_DF);
DoStuff();
return 0;
}
You would expect the memory used by S be freed when DoStuff() returns but Windows reports a memory leak here (320 bytes on my machine). However, if the length of S is set to >127 the memory leak is not reported (try std::string S(200, ' ')). I suspect STLport keeps a separate pool for short strings which is only released when the program terminates, but that's just a guess. Any explanations or workarounds are appreciated. I'm using VC6 with STLport 4.6.2.