Cwinthread memory release problem (VC ++ 6.0)

Source: Internet
Author: User

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 );
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.