如何说服内存管理器释放未使用的内存 [英] How to convince the memory manager to release unused memory

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

问题描述

在最近的帖子中(我的程序从不释放内存。为什么?)我表明使用FastMM时,该应用程序不会将大量内存释放回系统。
最近我创建了一个人工测试程序,以确保它不是内存问题,并且仅在FastMM中出现。

In a recent post ( My program never releases the memory back. Why? ) I show that when using FastMM, the application does not release substantial amounts of memory back to the system. Recently I created an artificial test program to make sure the issue it is not a memory and that it only appears with FastMM.

在此程序中,我创建并破坏了一个对象(与上一篇文章中使用的对象相同)500次。

In this program I create and destroy an object (same as the one used in the previous post) 500 times.

内存需求为(私有工作集):

没有FastMM

运行循环之前:1.2MB

运行循环后:2.1MB

Without FastMM
Before running the loop: 1.2MB
After running the loop: 2.1MB

使用FastMM(积极调试模式)

运行循环前:2.1MB

运行循环后:25MB

With FastMM (aggressive debug mode)
Before running the loop: 2.1MB
After running the loop: 25MB

使用FastMM(释放模式)

运行循环前:1.8 MB

运行循环后:3MB

With FastMM (release mode)
Before running the loop: 1.8MB
After running the loop: 3MB

如果我多次运行循环,则内存需求不会增加。这意味着未释放的内存将被重复使用,因此这不是内存泄漏(内存泄漏会增加内存占用量,每次运行会增加几KB / MB)。

If I run the loop several times, the memory requirement does not increase. Which means that the unreleased memory is re-used so this is not a memory leak (a memory leak would increase the memory footprint with several KB/MB at each run).

我的问题是:

如何在FastMM中禁用此行为?可能吗我知道,如果我在没有FastMM或没有FastMM释放模式的情况下释放程序,它将浪费适量的RAM。但是按需禁用此行为将有助于我(我们?)识别内存泄漏。实际上,在我的第一篇文章(请参阅链接)中,很多人建议我有漏洞。显然是由于此行为而造成的混乱。不,很明显没有泄漏。只是内存管理器拒绝释放大量内存。

How can I disable this behavior in FastMM? Is it even possible? I know, if I release the program without FastMM or with FastMM Release Mode it will "waste" moderate amounts of RAM. But disabling this behavior on demand, will help me (us?) identifying memory leaks. Actually in my first post (see link) many people suggested that I have a leak. The confusion was created obviously just because of this behavior. No, it is obvious there is no leak. It is just the memory manager that refuses to release large amounts of memory.

它会释放额外的内存吗?什么时候?是什么触发的?程序员可以触发它吗?例如,当我知道我已经完成了一个占用大量RAM的任务并且用户可能暂时不使用该程序(将其最小化)时,可以将RAM刷新回系统吗?当用户打开程序的多个实例时会发生什么?他们会争夺RAM吗?

It will ever release the extra memory? When? What triggers this? Can the programmer trigger it? For example when I know that I have finished a RAM-intensive task and the user may not use the program for a while (minimize it), can I flush the RAM back to the system? What happens when the user open multiple instances of my program? Won't they compete for RAM?

推荐答案

已解决

如Barry Kelly所建议,该内存将由FastaMM自动释放。
为了确认这一点,我创建了第二个分配了很多RAM的程序。 Windows用完RAM后,我的程序内存使用率立即恢复到其原始值。

As suggested by Barry Kelly the memory will be released automatically by FastaMM. To confirm that this 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.

问题已解决。
谢谢Barry。

Problem solved. Thanks Barry.

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

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