我的程序永远不会释放内存.为什么? [英] My program never releases the memory back. Why?

查看:36
本文介绍了我的程序永远不会释放内存.为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 MDI 程序.当它启动时,它需要 2-3MB 的 RAM.然后,在这个程序中,我创建了大约 260 个 MDI 子窗口(每个都有一个 TStringGrid、一个位图和一些其他控件)并显示一些数据.该应用程序需要大约 500MB 来加载所有这些窗口.如果我手动关闭每个 MDI 子项,应用程序仍使用 160MB 的 RAM.为什么它不返回几 MB 的 RAM?我应该担心这个吗?160MB 对于只有 1GB 或 RAM 的系统来说已经很多了!!

I have a MDI program. When It starts it takes 2-3MB of RAM. Then, in this program I create about 260 MDI child windows (each has a TStringGrid, a bitmap and some other controls) and display some data. The application needs about 500MB to load all those windows. If I close each MDI child manually, the application still uses 160MB of RAM. Why it doesn't return to few MB of RAM? Should I worry about this? 160MB it is A LOT for a system that has only 1GB or RAM!!

注意:我使用任务管理器中的 WORKING SET 列来查看 RAM 统计信息.也许我需要一个更好的工具来读取 RAM 利用率.(私有工作集只是比工作集小一点).

Note: I use the WORKING SET column in Task Manager to see RAM statistics. Maybe I need a better tool to read the RAM utilization. (Private Working Set is just a bit smaller than Working Set).

这不是泄漏!
FastMM(设置为激进)表示关闭程序时没有内存泄漏.请参阅我的回答帖子以获取其他证明它不是泄漏的证据.

This is not a leak!
FastMM (set on aggressive) indicates no memory leak when I close the program. See my Answer post for additional evidence that it isn't a leak.

我发布东西
许多人告诉我关闭子窗口只会隐藏它.我知道.我使用Action:= caFree"来实际发布表单.每个表单都负责释放它所拥有的控件.

I release stuff
Many people told me that closing a child window only hides it. I know that. I use "Action:= caFree" to actually release the forms. Each form is responsible for releasing the controls it holds.

回答
我发现 FastMM 对此负责.请参阅我在下面发布的答案.

Answer
I have found that FastMM is responsible for this. See the answer I posted below.

Delphi 7,Win 7 32 位
类似帖子:
内存可以清理吗?
何时调用 SetProcessWorkingSetSize?(说服内存管理器释放内存)

Delphi 7, Win 7 32 bit
Similar posts:
Can memory be cleaned up?
When to call SetProcessWorkingSetSize? (Convincing the memory manager to release the memory)

推荐答案

答案:

我刚刚从我的项目中删除了 FastMM,在释放所有这些子窗口后,程序又回到了几 MB.许多人可能会争辩说,这不是一种不当行为,FastMM 这样做是为了进行某种异常的内存优化.他们可能是真的.但是,它可能对我的应用程序有利,但对其他正在运行的应用程序可能不利.

I just removed FastMM from my project and the program returned to few MB after freeing all those child windows. Many may argue that this is not a misbehavior and that FastMM is doing this in order to do some kind of kinky memory optimizations. They may be true. However, it may be good for MY application but it may not be good of other running applications.

所以,至少我们知道是谁造成了这种情况.我一整天都担心程序会像旧桶一样泄漏 RAM.我现在放心了.

So, at least we know who causes this. I worried to a whole day that may program is leaking RAM like an old bucket. I am relieved now.

更新:

为了确认此行为是由 FastMM 生成的(如 Barry Kelly 所建议),我创建了第二个程序,该程序分配了大量 RAM.一旦 Windows 用完 RAM,我的程序内存利用率就会恢复到其原始值.
(注意:我不是说 FastMM 有 bug!)

To confirm that this behavior is generated by FastMM (as suggested by Barry Kelly) I created 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.
(Note: I am not saying there is a bug in FastMM!)

我的程序没有泄漏.问题解决了.

My program is not leaking. Problem solved.

这篇关于我的程序永远不会释放内存.为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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