可以清理记忆吗? [英] Can memory be cleaned up?

查看:218
本文介绍了可以清理记忆吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个Win32项目中使用Delphi 5(安装了FastMM),并且最近一直试图大大减少这个应用程序的内存使用量。到目前为止,我已经减少了一半的使用量,但是在单独的工作中发现了一些东西。当我最小化应用程序时,内存使用量从45千米缩小到1兆赫,这归因于它将其分页到磁盘。当我恢复并重新开始工作时,内存只上升到15兆。当我继续工作时,内存使用缓慢上升,最小化和恢复将其还原为15兆。所以就我的想法而言,当我的代码告诉系统释放内存的时候,它依然是依照Windows的,实际的垃圾收集不会直到很久才踢。



任何人都可以确认/拒绝这种行为?是否可以通过编程方式清除内存?如果我继续使用程序,而不用手动刷新,我会在一段时间后出现内存错误,并希望消除这种情况。谢谢。



编辑:我发现一篇关于 about.com ,这给了很多这样的内容以及其他内存管理领域的一些链接和数据。

解决方案

这是我们在 DSiWin32

 程序DSiTrimWorkingSet; 
var
hProcess:THandle;
begin
hProcess:= OpenProcess(PROCESS_SET_QUOTA,false,GetCurrentProcessId);
try
SetProcessWorkingSetSize(hProcess,$ FFFFFFFF,$ FFFFFFFF);
finally CloseHandle(hProcess);结束;
结束{DSiTrimWorkingSet}


I am working in Delphi 5 (with FastMM installed) on a Win32 project, and have recently been trying to drastically reduce the memory usage in this application. So far, I have cut the usage nearly in half, but noticed something when working on a separate task. When I minimized the application, the memory usage shrunk from 45 megs down to 1 meg, which I attributed to it paging out to disk. When I restored it and restarted working, the memory went up only to 15 megs. As I continued working, the memory usage slowly went up again, and a minimize and restore flushed it back down to 15 megs. So to my thinking, when my code tells the system to release the memory, it is still being held on to according to Windows, and the actual garbage collection doesn't kick in until a lot later.

Can anyone confirm/deny this sort of behavior? Is it possible to get the memory cleaned up programatically? If I keep using the program without doing this manual flush, I get an out of memory error after a while, and would like to eliminate that. Thanks.

Edit: I found an article on about.com that gives a lot of this as well as some links and data for other areas of memory management.

解决方案

This is what we use in DSiWin32:

procedure DSiTrimWorkingSet;
var
  hProcess: THandle;
begin
  hProcess := OpenProcess(PROCESS_SET_QUOTA, false, GetCurrentProcessId);
  try
    SetProcessWorkingSetSize(hProcess, $FFFFFFFF, $FFFFFFFF);
  finally CloseHandle(hProcess); end;
end; { DSiTrimWorkingSet }

这篇关于可以清理记忆吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆