Solved

CreateProcess resource allocation issue

Posted on 2004-04-30
4
198 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
  • 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

777 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