寻找“非泄漏”的策略或工具Delphi内存使用问题?

发布于 2024-12-10 16:09:52 字数 149 浏览 0 评论 0原文

服务器更新后,一个旧应用程序开始大量消耗内存。内存使用量似乎无限制地上升,直到程序挂起。

根据 FastMM4 和 EurekaLog,没有内存泄漏(28 字节除外),所以我假设应用程序关闭时所有内存都被释放。

有没有适合跟踪此类内存问题的工具或策略?

One old application started to consume memory a lot after server update. Memory usage seems to rise with out limit until program hangs.

According to FastMM4 and EurekaLog, there's no memory leak (except 28 bytes), so I assume all memory is freed when application is shutdown.

Are there any tools or strategies suitable for tracking this kind of memory problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

残疾 2024-12-17 16:09:52

自 2012 年 9 月以来,有一种非常简单且舒适的方法来查找此类“仅运行时”内存泄漏。

FastMM4991引入了一种新方法,LogMemoryManagerStateToFile

添加了 LogMemoryManagerStateToFile 调用。此调用记录了以下内容的摘要
文件的内存管理器状态:分配的总内存、开销、
效率,以及按类和字符串类型分配的内存的细分。
此调用可能有助于捕获不一定泄漏的对象,但是
停留的时间确实比他们应该停留的时间长。

要在运行时发现泄漏,您只需执行以下步骤,

  1. 在每隔一段时间调用 LogMemoryManagerStateToFile('memory.log', '') 的地方添加一个调用,
  2. 运行应用程序
  3. ,打开带有“tail”程序的日志文件(例如打开tail模式的Notepad++),当文件内容更改时会自动刷新观察
  4. 文件的第一行,它们将包含占用最高内存量的内存分配
  5. 如果您看到某个班级或内存类型的实例数量不断增加,这可能是泄漏的原因

Since September 2012, there is a very simple and comfortable way to find this type of "run-time only" memory leaks.

FastMM4991 introduced a new method, LogMemoryManagerStateToFile:

Added the LogMemoryManagerStateToFile call. This call logs a summary of
the memory manager state to file: The total allocated memory, overhead,
efficiency, and a breakdown of allocated memory by class and string type.
This call may be useful to catch objects that do not necessarily leak, but
do linger longer than they should.

To discover the leak at run time, you only need these steps

  1. add a call to LogMemoryManagerStateToFile('memory.log', '') in a place where it will be called in intervals
  2. run the application
  3. open the log file with a "tail" program (for example Notepad++ with tail mode switched on), which will auto-refresh when the file content changes
  4. watch the first lines of the file, they will contain the memory allocations which occupy the highest amount of memory
  5. if you see a class or memory type constantly has a growing number of instances, this can be the reason of your leak
一花一树开 2024-12-17 16:09:52
  1. 不断增长的内存消耗是一个应用程序问题。不是bug,可以发现FastMM4或者EurekaLog。从他们的角度来看 - 应用程序只是正确地使用内存。
  2. 使用 AQTime、MemProof(很难找到,D7 是最后支持的版本(?))、SleuthQA(类似于 MemProof)或类似的内存分析器,您可以实时跟踪应用程序外部的内存使用情况。
  3. 使用 FastMM4、GetMemoryManagerState / GetMemoryManagerUsageSummary 您可以跟踪应用程序的内存使用情况。将此信息输出到跟踪文件中并在运行后进行分析。或者为上述过程之一创建简单的包装函数,它将返回当前的内存使用情况。并从 IDE 调试器 Evalute/Modify 调用它,添加到 Watches 或调用 OutputDebugString,并查看当前内存使用情况。

请注意,如果内存被某些 DLL 占用,那么您可能无法使用 (3) 看到她的内存使用情况。使用(2)。

分析内存使用情况和应用程序执行的任务,您可能会发现导致内存使用量增加的原因。

  1. The growing memory consumption is an application issue. It is not a bug, which can discover FastMM4 or EurekaLog. As from they point of view - application just correctly uses the memory.
  2. Using AQTime, MemProof (hard to find, D7 is last supported version (?)), SleuthQA (similar to MemProof) or similar memory profilers, you can track the memory usage outside of application in real-time.
  3. Using FastMM4, GetMemoryManagerState / GetMemoryManagerUsageSummary you can track memory usage from application. Output this information into trace file and analyze it after run. Or make simple wrapping function for one of the above procedures, which will return curent memory usage. And call it from IDE Debugger Evalute / Modify, add to Watches or call OutputDebugString, and see the current memory usage.

Note, if memory is eated by some DLL then you may not see her memory usage using (3). Use (2).

Analyzing the memory usage and the tasks performed by the application, you may discover what leads to raised memory usage.

心是晴朗的。 2024-12-17 16:09:52

AQTime(一种非常昂贵的商业工具)可以报告您的内存使用情况,直至分配每个对象的源代码行。在内存使用量非常大的情况下,您可能需要 AQTime 功能来显示对象的数量以及每个对象的大小(总大小加上单个实例大小)。 AQTime 对我来说非常有用,从 Delphi 7 开始,以及所有更高版本,包括您的版本(2006)和最新版本(XE 和 XE2)。

随着程序内存使用量的增长,AQTime 可用于抓取运行时堆的“快照”,您可以使用它来了解应用程序的内存使用情况;正在创建什么,以及每个对象存在多少个。即使不存在泄漏,理解应用程序创建和管理的对象的运行时行为也非常重要,并且 AQTime 是我所知道的对于 Delphi 用户来说最强大的工具。

如果您愿意升级到 Delphi XE/XE2,您可能已经拥有 AQTime 的精简版,如果是这样,请检查一下。如果没有,我建议您尝试他们的演示。我不知道有任何免费或开源替代品可以提供相同的功能。

较少的功能可以通过编写大量跟踪消息或使用 FastMM 完全调试模式手动拼凑在一起。如果您可以将内存使用情况的完整转储写入一个非常大的文件中,您也许可以编写一些工具来解析并创建摘要。在这种情况下,我使用 FastMM 的问题是,您将被详细信息淹没,而无法准确提取有助于您了解情况的摘要信息。所以,你可以尝试编写自己的工具来总结内存使用情况。在一个应用程序中,我使用了一系列我知道会使用大量内存的组件,我在应用程序中编写了一个对话框,显示这些大型内存数据对象的当前内存使用情况。

AQTime (a commercial tool which is quite expensive) can report your memory usage, down to the line of source code that allocated each object. In the case of very large memory usage scenarios, you might want the AQTime functionality that can show the number of objects and the size (total plus individual instance size) for each object. AQTime worked great for me, starting with Delphi 7, and all later versions, including your version (2006) and the latest versions (XE and XE2).

As the program memory usage grows, AQTime can be used to grab "snapshots" of the runtime heap, you can use to understand memory usage of your application; What is being created, and how many of each object exists. Even when no leaks exist, understanding the runtime behaviour of your application in terms of the objects it creates and manages, is very important, and AQTime is the most powerful tool I know of for Delphi users.

If you are willing to upgrade to Delphi XE/XE2, you might have an included light version of AQTime already, if so, check it out. If not, I recommend you try their demo. I am unaware of any free or open source alternatives that can provide the same functionality.

Lesser functionality could be cobbled together manually by writing lots of trace messages, or using the FastMM full-debug-mode. If you could write a complete dump of your memory usage into a very large file, you might be able to write some tools to parse, and create a summary. The problem I have with FastMM in this case, is that you will be drowned in detail information, without the ability to extract exactly the summary information that helps you understand your situation. So, you can try to write your own tool to summarize the memory usage. In one application I had that used a series of components that I knew would use a lot of memory, I wrote a dialog box into my application that showed current memory usage by these large memory-blob-of-data objects.

赢得她心 2024-12-17 16:09:52

你有没有想过导致 IDE 的泄漏......它是如此巨大!

就我而言(2GB RAM)我执行下一步...
1.打开IDE
2.将其最小化近六个小时
3. 查看物理内存的使用情况

结果:
当 IDE 打开时(记住我也做了将其最小化的测试),它的 RAM 越来越多......直到不再有可用的 RAM。
它获得所有 2GB RAM + 所有页面文件硬盘空间(我将其配置为 4GB)
在不到 6 个小时的时间内(在 IDE 上什么都不做),它尝试使用超过 6GB 的空间。

这就是所谓的 IDE 引起的内存泄漏...我不在 IDE 上输入任何字母,不编译任何内容,甚至不打开任何项目...只是打开 IDE 并将其最小化...离开计算机而不执行任何操作大约六个小时内,IDE 消耗了 6GB 内存。

当然,在那之后,IDE 会以 SystemOutOfMemory 的烦人消息开始...我必须杀死它...然后所有 6GB 都被释放!

这到底什么时候才能解决?

请注意,我已经应用了所有补丁,我也在没有应用每个补丁/修补程序的情况下进行了测试,等等...

我得到的最好的结果是禁用工具上的一些选项,例如强调错误代码的选项等...所以到底为什么该选项有任何影响...我没有在 IDE 上输入任何内容(在测试中)...如果我禁用它,内存泄漏会减少很多...

当然,如果我使用 IDE(写打开的项目上的代码)甚至没有编译/运行它......事情变得很多更糟糕的是......不到一个小时就可以达到高达 6GB 的内存泄漏,有时在复制/粘贴源代码 15 分钟后发生。

看来短时间内是没有办法解决的!!!

所以我得到了下一个完美的解决方案:
- 关闭 IDE,每隔 15 分钟或更短时间重新打开它

丑陋的解决方案,我知道......但有效!

Have you ever think about the Leak that is causing the IDE... it is so huge!!!

In my case (2GB of RAM) i do the next...
1. Open the IDE
2. Leave it minimized for near six hours
3. See how Physical memory is getting used

The result:
While IDE is oppened (remember i also do the test having it minimized) it is getting more and more RAM... till no more ram free.
It gets all 2GB RAM + all Pagefile hard disk space (i have it configured to a mas of 4GB)
In less that six hours (doing nothing on IDE) it tries to use more than 6GB.

That is called a Memory Leak casused by the IDE... i do not type any letter on IDE, do not compile anything, do not even open any project... just open IDE and minimize it... leave the computer without doing anything on it for about six hours and IDE is consuming 6GB of memory.

Of course, after that, the IDE start with annoying messages of SystemOutOfMemory... and i must kill it... then all that 6GB are freed!!!

When on the hell will this get fixed?

Please note i have all patches applied, i also tested without applying each patch/hotfix, etc...

The best i got was dissabling some options on Tools, like the one that underlines bad code, etc... so why on the hell that option has any influence... i am not typing anything on the IDE (on the tests)... and if i have it dissabled the memory leak gets reduced a lot...

Of course, if i use the IDE (write code on an opened project) without even compiling / running it... the thing goes much more worst... memory leak upto 6GB can got reached on less than an hour, sometimes occurs after 15 minutes of Copy/Paste source code.

Seems there will not be a solution in a short time!!!

So i got the next solution that works perfect:
-Close the IDE an reopen it each 15 minutes or less

Ugly solution, i know... but works!!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文