std::string operator+() memory leak?

前端 未结 3 1998
南笙
南笙 2021-02-13 16:03

I\'m quite worry because I wrote a little application and it seems that there is a memory leak if I believe valgrind (What I actually do):

==9321== 251 bytes in          


        
3条回答
  •  遇见更好的自我
    2021-02-13 16:21

    I would not worry too much about STL leaks.

    The default STL allocator (for gcc) uses clever tricks to maximize efficiency that Valgrind often reports as leaks. Notably it pools memory, meaning that it keeps memory around when you clear a string and may reuse it next time you insert in a map or a vector for example.

    I don't think the pool itself is properly disposed of at the end of the program, probably to avoid the Static Destruction Order Fiasco (ie, imagine that the pool is disposed of and you then request memory, urk). Thus it leaks... right before your program ends and the OS gets the memory back forcefully.

提交回复
热议问题