何时调用SetProcessWorkingSetSize? (说服内存管理器释放内存) [英] When to call SetProcessWorkingSetSize? (Convincing the memory manager to release the memory)

查看:287
本文介绍了何时调用SetProcessWorkingSetSize? (说服内存管理器释放内存)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在上一篇文章中(我的程序永远不会释放内存。为什么?)我显示FastMM可以缓存(读取为自己保留)相当大量的内存。如果您的应用程序刚刚在RAM中加载了大量数据集,则在释放数据后,您将看到令人印象深刻的RAM不会释放回内存池。

In a previous post ( My program never releases the memory back. Why? ) I show that FastMM can cache (read as hold for itself) pretty large amounts of memory. If your application just loaded a large data set in RAM, after releasing the data, you will see that impressive amounts of RAM are not released back to the memory pool.

我环顾四周,似乎调用SetProcessWorkingSetSize API函数会将缓存刷新到磁盘。但是,我无法决定何时调用此功能。我想在OnClick事件结束时在执行RAM密集型操作的按钮上调用它。不过有人说这可能会导致AV。

I looked around and it seems that calling the SetProcessWorkingSetSize API function will "flush" the cache to disk. However, I cannot decide when to call this function. I wanted to call it at the end of the OnClick event on the button that is performing the RAM intensive operation. However, some people are saying that this may cause AV.

如果任何人成功使用此功能,请让我(我们)知道。

If anybody used this function successfully, please let me (us) know.

非常感谢

编辑:

1.发布数据集后,程序仍然需要大量随机存取存储器。调用SetProcessWorkingSetSize后,大小返回到几MB。有人认为没有任何东西被释放。我同意。但是内存脚打印现在很小,并且在正常使用程序后(例如执行不涉及加载大数据集的正常操作)时不会增加记忆体打印。不幸的是,没有办法证明交换到磁盘的内存被加载到内存中,但我认为不是。
2.我已经证明了(我希望)这不是内存泄漏:

我的程序永远不会释放内存。为什么?

如何说服内存管理器释放未使用的内存

推荐答案

问题解决:

我不需要使用SetProcessWorkingSetSize。 FastMM将最终释放RAM。

Problem solved:
I don't need to use SetProcessWorkingSetSize. FastMM will eventually release the RAM.

要确认此行为是由FastMM生成的(正如Barry Kelly所建议的)封装了分配了大量RAM的第二个程序。一旦Windows用完了RAM,我的程序内存利用率恢复到原来的值。

To confirm that this behavior is generated by FastMM (as suggested by Barry Kelly) I crated a second program that allocated A LOT of RAM. As soon as Windows ran out of RAM, my program memory utilization returned to its original value.

这篇关于何时调用SetProcessWorkingSetSize? (说服内存管理器释放内存)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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