在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
创建一个定时器,设置每隔N秒触发一次,也就是每隔多久进行一次内存清除!
//调用 procedure TfmMain.Timer1Timer(Sender: TObject); begin TClearMemory.Create(False); end;
unit ClearMemoryThread; interface uses Classes, SysUtils, Forms, Windows; type TClearMemory = class(TThread) private protected procedure Execute; override; public constructor Create(Suspended: Boolean); end; implementation //清理内存 procedure ClearMemory; begin if Win32Platform = VER_PLATFORM_WIN32_NT then begin SetProcessWorkingSetSize(GetCurrentProcess, $FFFFFFFF, $FFFFFFFF); Application.ProcessMessages; end; end; //创建线程 constructor TClearMemory.Create(Suspended: Boolean); begin inherited Create(Suspended); FreeOnTerminate := True; {这可以让线程执行完毕后随即释放} end; //线程启动 procedure TClearMemory.Execute; begin ClearMemory; end; end.
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论