Moment, ich kann dir gerade nicht folgen:
Meine erzeugte TStringList wird doch am Ende freigegeben, oder etwa nicht?
Delphi-Quellcode:
function TProcessHandler.GetAllRunningProcs: TStringList;
// returns all currently running processes
var
s: string;
sl: TStringList;
begin
Result := nil;
sl := TStringList.Create; // <--- HIER erzeuge ich es...
try
hProcSnap := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hProcSnap <> INVALID_HANDLE_VALUE) then
begin
pe32.dwSize := SizeOf(ProcessEntry32);
if (Process32First(hProcSnap, pe32)) then
begin
s := pe32.szExeFile;
sl.Add(s);
while Process32Next(hProcSnap, pe32) do
begin
s := pe32.szExeFile;
sl.Add(s);
end;
end;
Result := sl;
end;
CloseHandle(hProcSnap);
finally
sl := nil; // <--- HIER &
sl.Free; // <--- HIER wird´s doch wieder gelöscht?
end;
end;