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

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

问题描述

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



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



这不是一个泄漏!

FastMM (设置为主动)表示在关闭程序时没有内存泄漏。查看我的答复帖子,以获取额外的证据表明它不是泄漏。



我发布的东西

很多人告诉我关闭一个孩子的窗户只会隐藏它。我知道。我使用Action:= caFree来实际释放表单。



答案

我发现FastMM负责这个。查看我在下面发布的答案。






Delphi 7,Win 7 32位

相似的帖子:

可以清理内存吗? < br>
何时调用SetProcessWorkingSetSize? (说服内存管理器释放内存)

解决方案

答案: p>

我刚刚从我的项目中删除了FastMM,该程序在释放所有这些子窗口后返回到几MB。许多人可能会认为这不是一个不正当行为,而FastMM正在做这些事情来做某种恶意的内存优化。他们可能是真的然而,这可能对我的应用程序是有好处的,但它可能不适用于其他正在运行的应用程序。



所以,至少我们知道是谁造成的。我担心一整天可能程序正在泄漏的RAM像一个旧桶。我现在放心了为了确认这个行为是由FastMM生成的(正如Barry Kelly所建议的),我打了一个分配了大量RAM的第二个程序。一旦Windows用完了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!!

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).

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.

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.

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


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)

解决方案

Answer:

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.

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.

UPDATE:

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.

My program is not leaking. Problem solved.

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

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