Does std::string::clear and std::list::clear erases data from memory
c++, list, string
Solution
The memory isn't overwritten. It is not even guaranteed to be freed.
For example, if you create a huge string and call `clear` on it, only its size will be reduced, but the allocated memory may still be reserved. However, it will be freed if the string gets out of scope.
`std::list` at least guarantees that the elements inside the list will be destructed if you clear the list.
So, if your memory contains sensitive data, you should manually overwrite them.
Problem
In the description of the string::clear function, it says: clear: Erases the contents of the string, which becomes an empty string (with a length of 0 characters). In the description of the list::clear function, it says: clear: Removes all elements from the list container (which are destroyed), and leaving the container with a size of 0. Does the clear overwrite the memory of the string and the list or just free them?