可以清理记忆吗? [英] Can memory be cleaned up?
问题描述
任何人都可以确认/拒绝这种行为?是否可以通过编程方式清除内存?如果我继续使用程序,而不用手动刷新,我会在一段时间后出现内存错误,并希望消除这种情况。谢谢。
编辑:我发现一篇关于 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屋!