Do I need to remove the static std :: map?

In some classes, I have a static std :: map with pointers inside. My question is: if I need to delete at the end of the program or this memory will automatically be freed. My problem is that the pointers stored internally are deleted through our destructors when std :: map is deleted.

Thank.

+3
source share
7 answers

If the map contains pointers that were allocated using new (or new [] or malloc ), then each pointer needs a corresponding delete (or delete [] or free ).

, . , , boost smart , ++ 0x . std:: auto_ptr STL. , .

Edit:

, boost:: ptr_map .

+6

, . , , , . , , Boost shared_ptr . .

: Boost ptr_map .

+2

" " , , , , . , RAII.

+1

std::map delete . , , , , .

+1

, "", , "", . , , , ( ), .

0

"" - , , . , , , , .

, , valgrind .. .

, , valgrind, , , "", . , , .. , ( malloc new []).

"", . , ( ), . , , .

0

, : , . . , .

-1

Source: https://habr.com/ru/post/1786177/


All Articles