delphi 内存管理,定期释放。
创建一个定时器,设置每隔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.
posted on 2010-12-15 00:11 Delphi2010_老赵 阅读(1598) 评论(0) 编辑 收藏 举报