Link to home
Start Free TrialLog in
Avatar of wipnav
wipnav

asked on

CreateProcess resource allocation issue

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
Avatar of geobul
geobul

Hi,

Add these two lines at the end of your code:

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

Regards, Geo
ASKER CERTIFIED SOLUTION
Avatar of geobul
geobul

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of wipnav

ASKER

Geo,

Perfect!

Thank you very much.

Regards,

Bill
You are welcome :-)