C++'s std::string pools, debug builds? std::string and valgrind problems

前端 未结 6 639
旧巷少年郎
旧巷少年郎 2021-01-11 16:38

I have a problem with many valgrind warnings about possible memory leaks in std::string, like this one:

120 bytes in 4 blocks are possibly lost in loss recor         


        
6条回答
  •  [愿得一人]
    2021-01-11 17:22

    Check the FAQ. There is a section about “Memory leaks” in containers. You should

    • check your version of Valgrind
    • use a debug build of your program (and un-optimized)
    • and define GLIBCXX_FORCE_NEW if necessary. (This is an environment variable that affects your program's runtime behavior, not a compile-time #define as you might expect.)

提交回复
热议问题