DELPHI独自のタイマータイミングクリーンアップメモリを作成


   google , CSDN , 。 。
unit TrimWorkingSet;

interface

implementation

uses
  SysUtils, Windows, ExtCtrls;

type
  TTrimmer = class(TTimer) // TTimer 
  public
    procedure TimerTick(Sender: TObject);
  end;

procedure TTrimmer.TimerTick(Sender: TObject);
var
  CurrentPID, FocusedPID: THandle;
begin
  CurrentPID := GetCurrentProcessId;// ID
  GetWindowThreadProcessId(GetForegroundWindow, @FocusedPID);// ID
  if (Win32Platform = VER_PLATFORM_WIN32_NT) and // windows NT       (CurrentPID <> FocusedPID) then             //      SetProcessWorkingSetSize(CurrentPID, Cardinal(-1), Cardinal(-1) );
end;

var
  Timer: TTrimmer;

initialization
  Timer := TTrimmer.Create(nil);
  Timer.Interval := 30000;// 
  Timer.OnTimer := Timer.TimerTick;
finalization
  if Assigned(Timer) then
    Timer.Free;
end.