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.
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 .
, . , , , . , , Boost shared_ptr . .
: Boost ptr_map .
" " , , , , . , RAII.
std::map delete . , , , , .
std::map
delete
, "", , "", . , , , ( ), .
"" - , , . , , , , .
, , valgrind .. .
, , valgrind, , , "", . , , .. , ( malloc new []).
"", . , ( ), . , , .
, : , . . , .
Source: https://habr.com/ru/post/1786177/More articles:Как запускать команды терминала Mac OS с Java (с использованием времени выполнения?) - javaXAML editing options - wpfPowershell using Regex finding a string inside a string - substringHow to find out how much memory an Android app has left to use? - javacURL returns XML or JSON - jsonWhy so much memory? - androidCan I disable the SharpDevelop design view to set the property value in the InitializeComponent? - c #Entering Type Type Parameters with AutoFac - genericsCannot bulk insert using NHibernate - bulkinsertConvert ControlTemplate XAML to C # - c #All Articles