Solved

CreateProcess resource allocation issue

Posted on 2004-04-30
4
201 Views
Last Modified: 2010-04-05
Hi,

I am creating a process from my Delphi 7 application. I wait for it to complete and then continue execution of my program. Here is my code:

FillChar(StartupInfo, SizeOf(StartupInfo), 0);
FillChar(ProcessInfo, SizeOf(ProcessInfo), 0);
if CreateProcess(nil, PChar(CommandLine), nil, nil, True, 0, nil, nil, StartupInfo, ProcessInfo) then
  repeat
    Application.ProcessMessages;
    GetExitCodeProcess(ProcessInfo.hProcess, ExitCode);
  until (ExitCode <> STILL_ACTIVE) or Application.Terminated;

It works fine. My problem is that Memory Sleuth indicates that there is a Thread Handle and a Process Handle still allocated once my application terminates.

My question is, how do I free these resources?

Regards,

Bill
0
Comment
Question by:wipnav
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 17

Expert Comment

by:geobul
ID: 10961724
Hi,

Add these two lines at the end of your code:

CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread );

Regards, Geo
0
 
LVL 17

Accepted Solution

by:
geobul earned 250 total points
ID: 10961750
if CreateProcess(nil, PChar(CommandLine), nil, nil, True, 0, nil, nil, StartupInfo, ProcessInfo) then
  try
    repeat
      Application.ProcessMessages;
      GetExitCodeProcess(ProcessInfo.hProcess, ExitCode);
    until (ExitCode <> STILL_ACTIVE) or Application.Terminated;
  finally
    CloseHandle(ProcessInfo.hProcess);
    CloseHandle(ProcessInfo.hThread );
  end;

Regards, Geo
0
 
LVL 1

Author Comment

by:wipnav
ID: 10961914
Geo,

Perfect!

Thank you very much.

Regards,

Bill
0
 
LVL 17

Expert Comment

by:geobul
ID: 10962050
You are welcome :-)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question