I have the following string class inheriting from MFC CString
class TString : public CString
{
public:
TString() : CString(_T(""))
{
}
TString(LPCTSTR str) : CString(str)
{
}
};
I had a memory exception in a method that often used the + operator with TString, so I tried to do a test like this
TString str;
TCHAR buffer[] = "Hello world, Hello world, Hello world, Hello world, Hello world, Hello world";
uint i = 0;
while(i++ < 100000000)
{
str = buffer;
str += buffer;
}
which took up a lot of memory and ended with an exception from memory, this is a shot to change memory from the task manager after the last code was executed

when I replaced TString with CString, it was normal, it took time and memory deletion and the memory was stable in the task manager, as in this picture

I tried the following 2 states
- I created another exe application that depends on the same Library that contains the TString class, which worked very well, like CString
- Sleep (1) while,
, ?
EDIT:
, . CString , std::string. , , malloc , , , CWinAppEx, , InitInstance. 4
int tmpDbgFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
tmpDbgFlag |= _CRTDBG_DELAY_FREE_MEM_DF;//<====this is the evil after comment everything is fine
tmpDbgFlag |= _CRTDBG_LEAK_CHECK_DF;
_CrtSetDbgFlag(tmpDbgFlag);
, . .
tmpDbgFlag | = _CRTDBG_DELAY_FREE_MEM_DF;
.
, , , .