内存可以清理吗? [英] Can memory be cleaned up?

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

问题描述

我在一个 Win32 项目中使用 Delphi 5(安装了 FastMM),最近一直在尝试大幅减少此应用程序中的内存使用量.到目前为止,我已经将使用量减少了近一半,但在处理单独的任务时注意到了一些事情.当我最小化应用程序时,内存使用量从 45 兆减少到 1 兆,我将其归因于它分页到磁盘.当我恢复它并重新开始工作时,内存只增加到 15 兆.当我继续工作时,内存使用量再次缓慢上升,最小化和恢复将其刷新回 15 兆.所以在我看来,当我的代码告诉系统释放内存时,它仍然被 Windows 保留,并且实际的垃圾收集直到很久以后才开始.

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.

我发现了一篇关于 关于.com 提供了很多这样的内容以及一些用于其他内存管理领域的链接和数据.

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.

推荐答案

这是我们在 中使用的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天全站免登陆