Situation: Recently learned the old code, found the application memory, and then the pointer to the thread callback function, but never found the place to release. So write below the small demo to learn under.
#include "stdafx.h" #include <iostream> #include <atlstr.h> #include <iostream> using namespace std; DWORD WINAPI Testthreadproc (lpvoid lpparameter) {if (NULL! = lpparameter) {delete [] lpparameter;//If you comment out this sentence, in the Task Manager
You will see that the memory is constantly rising.
Lpparameter = NULL;
} cout << "Test thread End:" << Endl;
return 0;
} int _tmain (int argc, _tchar* argv[]) {DWORD dwthreadid;
for (int i = 0; i < ++i) {int* pInt = new int[1000 * 10000];
if (NULL = = pInt) {cout << "Allocate Memory Failed:" << Endl;
Break
} HANDLE hthread = CreateThread (NULL, 1024x768 * 1024x768 *, Testthreadproc, pInt, 0, &dwthreadid);
if (NULL = = hthread) {cout << "Create Thread Failed ..." << Endl;
Note the thread creation failure also frees the memory to release if (NULL! = pInt) {delete [] pInt;
PInt = NULL;
}} else {cout << "Create Thread successed ..." << Endl; } Sleep (1000);
Easy to Observe} return 0; }