When cwinthread is started, it is suspended and cannot be released clean.
Run the following code. We can see that the memory of the task manager is growing rapidly and Memory leakage occurs.
(P is the pointer of the current class object, and the function passed to the thread function is to let the thread callback class member variable)
While (true)
{
Sleep (100 );
If (p-> TH! = NULL)
{
P-> TH-> exitinstance ();
Closehandle (p-> TH-> m_hthread );
}
P-> TH = afxbeginthread (function, (lpvoid) P, thread_priority_normal, 0, create_suincluded, null );
P-> TH-> m_bautodelete = false;
}
The following code does not show memory growth:
While (true)
{
Sleep (100 );
If (p-> TH! = NULL)
{
P-> TH-> exitinstance ();
Closehandle (p-> TH-> m_hthread );
}
P-> TH = afxbeginthread (function, (lpvoid) P );
P-> TH-> m_bautodelete = false;
}
Similar to releasing cwinthread itself
Memory growth will occur as follows:
While (true)
{
Sleep (100 );
P-> TH = afxbeginthread (function, (lpvoid) P, thread_priority_normal, 0, create_suincluded, null );
}
The following code does not show memory growth:
While (true)
{
Sleep (100 );
P-> TH = afxbeginthread (function, (lpvoid) P );
}