Einzelnen Beitrag anzeigen

Phantom1

Registriert seit: 20. Jun 2003
282 Beiträge
 
Delphi 10.4 Sydney
 
#5

Re: Speicherleck, laufende Prozesse abfragen

  Alt 8. Sep 2006, 11:04
Vielen dank für eure Tipps, leider besteht das Problem weiterhin.

Hier nochmal der gesamte Code, mit eueren Tipps:
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    Timer1: TTimer;
    procedure Timer1Timer(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
[img]
implementation

{$R *.dfm}

uses TLHelp32;

function GetProcessPath(ProcID: DWORD): string;
var
  me32: TModuleEntry32;
  hSnap : THandle;
begin
  Result := '';
  hSnap := CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, ProcID);
  if hSnap <> INVALID_HANDLE_VALUE then
    try
      me32.dwSize := sizeof(me32);
      Module32First(hSnap, me32);
      Result := me32.szExePath;
    finally
      CloseHandle(hSnap);
    end;
end;

procedure GetProcessSnapshot(sl: TStringList);
var
  hSnap: THandle;
  ProcEntry: TProcessEntry32;
  fn: TFileName;
begin
  hSnap:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  if hSnap<>INVALID_HANDLE_VALUE then
    try
      ProcEntry.dwSize:=SizeOf(ProcEntry);
      if Process32First(hSnap, ProcEntry) then
        while Process32Next(hSnap, ProcEntry) do begin
          fn:=AnsiLowerCase(GetProcessPath(ProcEntry.th32ProcessID));
          if (fn<>'') and (pos('explorer.exe', fn)=0) then
            sl.Add(fn);
        end;
    finally
      CloseHandle(hSnap);
    end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Timer1.Enabled:=False;

  ListBox1.Clear;
  GetProcessSnapshot(TStringList(ListBox1.Items));

  Timer1.Enabled:=True;
end;

end.
Inzwischen konnte ich das Problem etwas eingrenzen: Wenn ich nämlich die function GetProcessPath weglasse, dann läuft alles normal. Es muss also irgendwie an dieser function liegen.

So sieht es normalerweise im Taskmanager aus:
http://www.dreamer.homeip.net/easyto...n_normal_1.jpg

wenn ich jetzt jedoch den Code bzw das Programm starte, sieht es nach wenigen Minuten so hier aus:
http://www.dreamer.homeip.net/easytoolz/Taskman_4.jpg

mfg
  Mit Zitat antworten Zitat