【发布时间】:2015-07-15 06:21:58
【问题描述】:
我有一个服务,它创建一个进程,然后释放它的内存。 我使用 createprocess() 函数,然后关闭进程和线程的句柄, 这是我的代码:
if (CreateProcessA(NULL,
zAppName,//{ pointer to command line string }
NULL, //{ pointer to process security attributes }
NULL, //{ pointer to thread security attributes }
TRUE, //{ handle inheritance flag }
0,
NULL, //{ pointer to new environment block }
NULL, //{ pointer to current directory name }
&StartupInfo, //{ pointer to STARTUPINFO }
&ProcessInfo))
{
WaitForSingleObject(ProcessInfo.hProcess,WaitMiliSec);
GetExitCodeProcess(ProcessInfo.hProcess, &Result);
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);
CloseHandle(hRead);
CloseHandle(hWrite);
return (Result);
}
但是经过closehandle()函数后,hProcess和hThread还是有值的!!! 并且每次我的服务运行此代码时,内存都会增加并且不会减少!这是内存泄漏吗? 我该怎么办?
【问题讨论】:
-
从句柄仍有其价值这一事实并不意味着该进程还活着。
-
但是内存呢?当进程释放它!?(@marom)
-
你有理由相信一些内存没有被释放吗?只是你自己程序中的一些 int 值没有任何意义。
-
是的,在我创建进程后内存增加了,我在taskmanager中看到了,在我关闭句柄并且函数结束后,内存没有释放(@deviantfan)
-
WaitMiliSec 有多长,您确定它足够长以终止进程吗?