CreateProcess内存泄漏
一个程序A,使用CreateProcess调用另一个程序B多次,比如100,000次之后(B每次都主动 exit(0) ),任务管理器中显示A内存使用不变.
但整个WINDOWS内存使用量剧增.关掉A后,WINDOWS内存使用量会大量降下来。
是不是CreateProcess使用后,程序要主动销destroy什么东西?或是下面代码有什么问题?
代码如下:
/////////////////////////////////
long CRunTestApp::RunAndWait(CString as_command, bool ab_wait)
{
STARTUPINFOA lstr_startup;
lstr_startup.cb = 68;
lstr_startup.lpReserved = NULL;
lstr_startup.lpDesktop = NULL;
lstr_startup.lpTitle = NULL;
lstr_startup.dwX = 0;
lstr_startup.dwY = 0;
lstr_startup.dwXSize = 0;
lstr_startup.dwYSize = 0;
lstr_startup.dwXCountChars = 0;
lstr_startup.dwYCountChars = 0;
lstr_startup.dwFillAttribute = NULL;
lstr_startup.dwFlags = 1;
lstr_startup.wShowWindow = SW_SHOWNORMAL ;
lstr_startup.cbReserved2 = 0;
lstr_startup.lpReserved2 = NULL;
lstr_startup.hStdInput = NULL;
lstr_startup.hStdOutput = NULL;
lstr_startup.hStdError = NULL;
PROCESS_INFORMATION ls_info;
long i;
i = strlen(as_command)+1;
char * lc_command = new char[i];
// char lc_command[1024 * 4];
strcpy(lc_command,as_command);
if (CreateProcess(NULL,lc_command,NULL,NULL,NULL,NULL,NULL,NULL,&lstr_startup,&ls_info)){
if (ab_wait){
WaitForSingleObject(ls_info.hProcess,INFINITE);
}
delete []lc_command;
return 0;
}
delete []lc_command;
return -1;
}
/////////////////////////////////
VC6的完整工程在这里:
http://www.shuct.net/down.asp?id=20141110174316&check=A1701A01FEDBAAF11267021E047E6F49
其中,
CRunTestDlg::OnOK()
调用theApp.RunAndWait运行自己1000次
运行后,可以看到,在任务管理器中,内存使用多了几十M,当关掉后,内存就掉回去了