EDIT:
I decide rewrite my question to more simple because nobody was understands what I wanted to "say" in previously updated question and I discovered that it is not problem with my usage of new
and delete
, but somewhere else.
If I use inside class test_mem
code type_string = typeid(*this).name();
and use Diagnostic Tool while debug, and take memory snapshots under breakpoints (Memory Usage is turned on), I got this Allocations (Diff): when objects are created +4 and when destroyed -3.
When I remove inside constructor type_string = typeid(*this).name();
, Allocations are same (+x -x).
Then question is, can I ignore this Allocation +4 -3 (Diagnostic Tool)`? And why those Allocations are different, it does mean string doesn't delete its chars?
Here is source code, you can try it.
#include <iostream>
#include <string>
#include <typeinfo>
class test_mem
{
std::string type_string;
public:
test_mem()
{
type_string = typeid(*this).name();
}
std::string get_type() { return type_string; }
};
// -----------------------------------------------
void memory_test()
{
test_mem tm1; // use breakpoint here and take snapshot
test_mem tm2;
test_mem tm3;
test_mem tm4;
} // use breakpoint here and take snapshot (Allocation is +XX)
// -----------------------------------------------
int main()
{
memory_test();
return 0; // use breakpoint here and take snapshot (Allocation is -XX)
}