寻找“非泄漏”的策略或工具Delphi内存使用问题?
服务器更新后,一个旧应用程序开始大量消耗内存。内存使用量似乎无限制地上升,直到程序挂起。
根据 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
自 2012 年 9 月以来,有一种非常简单且舒适的方法来查找此类“仅运行时”内存泄漏。
FastMM4991引入了一种新方法,
LogMemoryManagerStateToFile
:要在运行时发现泄漏,您只需执行以下步骤,
LogMemoryManagerStateToFile('memory.log', '')
的地方添加一个调用,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
:To discover the leak at run time, you only need these steps
LogMemoryManagerStateToFile('memory.log', '')
in a place where it will be called in intervals请注意,如果内存被某些 DLL 占用,那么您可能无法使用 (3) 看到她的内存使用情况。使用(2)。
分析内存使用情况和应用程序执行的任务,您可能会发现导致内存使用量增加的原因。
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.
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.
你有没有想过导致 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!!!