简体   繁体   English

Delphi 7.0和内存泄漏?

[英]Delphi 7.0 and memory leak?

After spending time with FastMM4 in weeding out any pieces of code that could possibly cause memory leak as indicated by FastMM4, we have been test running our software for about a month non-stop on Windows 7. This is what I am seeing so far in the Task Manager for my software process. 花了很多时间用FastMM4清除任何可能导致内存泄漏的代码片段,如FastMM4所示,我们已经在Windows 7上测试运行我们的软件大约一个月了。这就是我目前所看到的我的软件过程的任务管理器。

> -CPU started out at 1% and 0%. Now it is bouncing around from 2% to 5%
> -VM usage started out at 11,852KB. Now it is at 4,900kb but bouncing
> around from 4,900kb to 5,000kb.

Does this mean we have memory leak in our software? 这是否意味着我们的软件中存在内存泄漏? I am confused and concerned. 我感到困惑和担忧。

Thanks in advance, 提前致谢,

不,当内存使用率上升并且最终您的应用程序使用所有可用内存时,您会发生内存泄漏并有理由担心。

That sounds like pretty normal memory usage. 这听起来像是非常正常的内存使用。 The program does something that needs memory, and memory usage goes up. 该程序执行需要内存的操作,并且内存使用量会增加。 The program gets done with what it's doing and releases the memory, and memory usage goes back down. 该程序完成它正在做的事情并释放内存,内存使用率回落。 A memory leak is when memory usage goes up and keeps going up because you're not releasing the memory once you're done with it. 内存泄漏是指内存使用率上升并持续上升,因为一旦完成内存,您就不会释放内存。

If you've got FastMM4, you shouldn't have to hunt around for things that might possibly cause a memory leak. 如果你有FastMM4,你不应该寻找可能导致内存泄漏的事情。 Just turn on Full Debug Mode and the logging option and it will find any memory that leaks when you run it, and write out a file with types and stack traces for you. 只需启用完全调试模式和日志记录选项,它就会找到运行时泄漏的任何内存,并为您写出包含类型和堆栈跟踪的文件。

Even if an application seems to run fine for days, there still can be memory leaks hidden in code areas which are not (or not frequently) used. 即使应用程序似乎运行好几天,仍然可能存在隐藏在代码区域中的内存泄漏,而代码区域没有(或不经常)使用。 So they can be a problem, when this part of the application becomes active some time later. 因此,当应用程序的这部分在一段时间后变为活动状态时,它们可能会成为一个问题。

To make sure that all code is tested for leaks, you can use FastMM4 with unit tests (with DUnit ), ensuring to execute as many code paths as possible. 为了确保所有代码都经过泄漏测试,您可以将FastMM4与单元测试(使用DUnit )一起使用,确保尽可能多地执行代码路径。 Unit test code coverage can be measured for example with this open source Delphi tool , or Discover which recently became open source . 可以使用这个开源Delphi工具或最近成为开源的 Discover来测量单元测试代码覆盖率。

Also, DUnit in the trunk version (9.4.0) supports automatic memory leak detection (based on FastMM4) for every test case. 此外,主干版本(9.4.0)中的DUnit支持每个测试用例的自动内存泄漏检测(基于FastMM4)。

May be worth to think about the debugger? 可能值得考虑一下调试器吗? I've understood that you do not use them. 我知道你不使用它们。 I also had problems with memory leaks. 我也有内存泄漏问题。 I just had no guessed about it. 我没想到它。 Now use the "guardian" of the leaks - for me it became deleaker. 现在使用漏洞的“监护人” - 对我而言,它变成了删除者。 And you can look such one, that will please you. 你可以看一下,这会让你高兴。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM