Limpar Memória virtual

Delphi

30/04/2013

Boa noite.

Tenho a seguinte função dentro de um Timer

function ProcessoExiste(ExeFileName: string): boolean;
const
  PROCESS_TERMINATE = $0001;
var
  ContinueLoop: BOOL;
  FSnapshotHandle: THandle;
  FProcessEntry32: TProcessEntry32{declarar Uses Tlhelp32};
  sai : integer;
begin
  result := false;

  FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
  ContinueLoop := Process32First(FSnapshotHandle,FProcessEntry32);
  sai := integer(ContinueLoop);

  while sai <> 0 do
    begin
      if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) = UpperCase(ExeFileName))
      or (UpperCase(FProcessEntry32.szExeFile) = UpperCase(ExeFileName))) then
        begin
          Result := true;
          sai := 0;
        end
      else
        begin
          ContinueLoop := Process32Next(FSnapshotHandle,FProcessEntry32);
          sai := integer(ContinueLoop);
        end;
    end;
  CloseHandle(FSnapshotHandle);  
end;



Com o tempo a memória de paginação do servidor é consumida por completo. Estou usando Delphi XE 2.
Gostaria de saber se existe outra função que me retorne os processos que estão em execução ou se tem alguma forma de limpar a memória após a chamada dessa função.

Grato pela atenção.
Hacson Alexandre

Hacson Alexandre

Curtidas 0

Respostas

Leonardo Xavier

Leonardo Xavier

30/04/2013

Eu utilizo a seguinte função veja se resolve o seu problema.
Function Func_ProgramaAberto(ExeFileName: String): Boolean;
const
PROCESS_TERMINATE = $0001;
var
ContinueLoop: BOOL;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32 ;
begin
Result := False;
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := sizeof(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
while Integer(ContinueLoop) <> 0 do
begin
if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) = UpperCase
(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) = UpperCase
(ExeFileName))) then
begin
KillTask('Make.exe');
Result := True;
Exit;
end;
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
end;
GOSTEI 0
POSTAR