Page 1 of 1
OpenProcess & Closehandle
Posted: Fri Mar 30, 2012 9:30 am
by PeterBotes
Hi all,
I am getting a handle to a process via OpenProcess_ but what happens if the process exists, how can I close the handle? and what happens if I don't close it? do I eventually run out of handles!
Reason I ask is I appear to have a handle leak and this is the only thing I can see that might cause it.
Thanks
Pete.
Re: OpenProcess & Closehandle
Posted: Fri Mar 30, 2012 9:57 am
by Fred
You can close the handle anytime, even if the subprocess is finished. The handle is not related to the program execution. If you don't need the handle, you can just close it after the OpenProcess call.
Re: OpenProcess & Closehandle
Posted: Fri Mar 30, 2012 1:59 pm
by Baldrick
I had a similar problem just recently with a program I wrote to poll monitor some network server software in a data center. My app certainly fixed all the issues with the 3rd party software which was continually crashing so my app auto restarts it & sets all it parameters as needed now whenever this happens, unfortunately I missed closing 2 handles in my own program. After about a month of continuous running 1 of the computers actually bugged out with an "out of memory" error. Once I took a close look at the code I had written, I found these 2 handles & put a close handle on each. Since this these servers have not missed a beat. 1 of the handles is coming from the OpenProcess_() API you refer to, so I would recommend closing when you no longer need it.