Yesturday I chased down a memory leak being reported by our leak
detection library. It lead me to question this line of code:
str_instance = std::string();
I changed it to str_instance.clear() and the leak went away.
"str_instance" is an instance variable in a class that had the above
line in one of its member functions. I would get one reported "leak"
for each of the objects instantiated (outer class, not string) even
though I could verify without doubt that all objects were getting
deleted before the memory leak detection thing went about its work.
The memory the leaked pointer was pointing to was the internal char
buffer of a std::string.
It was my understanding that the above line of code was ok, even if
clear() is better anyway. str_instance should get destroyed and then
recreated with the copy constructor...right?
It isn't a big thing. The "leak" is fixed and the fix is the better
way to do what is desired, but it still leaves me with doubt and a
possible confusion about how the above code is supposed to work.