Einzelnen Beitrag anzeigen

Benutzerbild von Union
Union

Registriert seit: 18. Mär 2004
Ort: Luxembourg
3.487 Beiträge
 
Delphi 7 Enterprise
 
#5

Re: Memory Leak bei FindFirst/TSearchRec trotz FileClose

  Alt 21. Jan 2009, 15:38
Es liegt daran, dass Du globale Variablen verwendest. Lagerstr Du alles in eine separate Prozedur aus, gibt es kein Speicherleck:
Delphi-Quellcode:
procedure FindLogFiles;
var
  loc_path: String;
  loc_dummy: String;
  loc_sr: TSearchRec;
begin
  loc_path := 'C:\Temp\';
  loc_dummy := 'TestFile.log';
  if FindFirst(loc_path + '*.log', faAnyFile - faDirectory, loc_sr) = 0 then
    try
      repeat
        if (SameText(loc_dummy, loc_sr.Name)) then begin
          Writeln('Found file: ' + loc_sr.Name);
        end;
      until (FindNext(loc_sr) <> 0);
    finally
      FindClose(loc_sr);
    end;
  { Free memory of string vars }
  loc_path := '';
  loc_dummy := '';
end;

begin
   FindLogFiles;
end.
Oder, alternativ mit Finalize(loc_sr).
Ibi fas ubi proxima merces
sudo /Developer/Library/uninstall-devtools --mode=all
  Mit Zitat antworten Zitat