FastMM4、Delphi6、TApplication 泄漏?

发布于 2024-10-17 02:43:49 字数 296 浏览 2 评论 0原文

我用D6检查了FastMM4。 当我使用“Forms”调试一个简单的应用程序时,每次都会出现 3 行内存泄漏。

此应用程序存在内存泄漏。 小块泄漏是(不包括 由指针注册的预期泄漏):

13 - 20 字节:TObjectList x 3, 未知 x 3 29 - 36 字节: TWinHelpViewer x 1 37 - 52 字节: 帮助管理器 x 1

这正常吗?

这是什么原因造成的?

谢谢: DD

I checked the FastMM4 with D6.
When I debug a simple application with uses "Forms", I everytime got 3 lines for memory leak.

This application has leaked memory.
The small block leaks are (excluding
expected leaks registered by pointer):

13 - 20 bytes: TObjectList x 3,
Unknown x 3 29 - 36 bytes:
TWinHelpViewer x 1 37 - 52 bytes:
THelpManager x 1

Is this normal?

Which thing causes this?

Thanks:
dd

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

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

发布评论

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

评论(2

萌化 2024-10-24 02:43:49

Delphi 6 附带的 RTL/VCL 包含一些内存泄漏。在 Delphi 的后续版本中,FastMM 的使用导致这些内存泄漏被从 RTL/VCL 中删除。

您需要做的就是使用 FastMM 注册这些已知的和预期的内存泄漏。一旦您注册了泄漏,FastMM 就不会报告它们。尽管这些泄漏是真实存在的,但由于各种原因,最好忽略它们:

  • 这些已知的 VCL 泄漏所泄漏的内存很小,并且在进程的生命周期内不会增长。
  • 无论如何,一旦进程终止,内存就会返回系统。
  • 由于代码泄漏超出了您的控制范围,因此您无能为力。您可以修复它们并使用您自己的 VCL 单元版本,但这值得吗?

这些泄漏唯一可能产生影响的情况是,如果您的 DLL 在该进程的生命周期内从同一进程加载和卸载了数千次。我不认为这是一个非常现实的场景。

如果您不注册泄漏,那么 FastMM 泄漏报告将变得基本上无效,因为它每次都会显示。如果每次你学会忽略它时都会出现。此泄漏报告非常有价值,但只有当它显示您可以控制的泄漏时才有价值。

在我的 Delphi 6 项目中,我的 .dpr 文件中有以下代码:

// Register expected VCL memory leaks caused by Delphi unit HelpIntfs.
FastMM4.RegisterExpectedMemoryLeak(36, 2); // THelpManager x 1, THTMLHelpViewer x 1
FastMM4.RegisterExpectedMemoryLeak(20, 7); // TObjectList x 3, THelpSelector x 1, Unknown x 3
FastMM4.RegisterExpectedMemoryLeak(52);    // TWinHelpViewer x 1

我的应用程序中的所有表单均从其后代中继承,在 TForm 后代中也有以下代码:

var
  ExpectedHelpStringMemoryLeakRegistered: Boolean;

procedure TMyForm.WMHelp(var Message: TWMHelp);
begin
  if not (biHelp in BorderIcons) and not ExpectedHelpStringMemoryLeakRegistered then begin
    // Register expected VCL memory leaks caused by Delphi unit HelpIntfs.
    FastMM4.RegisterExpectedMemoryLeak(44); // TString x 1
    ExpectedHelpStringMemoryLeakRegistered := True;
  end;
  inherited;
end;

具体取决于您在RTL/VCL以及你如何使用它们,你可能需要注册不同的内存泄漏。

The RTL/VCL that ships with Delphi 6 contains some memory leaks. In later releases of Delphi the use of FastMM led to these memory leaks being removed from the RTL/VCL.

What you need to do is register these known and expected memory leaks with FastMM. Once you have registered the leaks that FastMM won't report them. Although these leaks are real, they are best ignored for various reasons:

  • The leaked memory from these known VCL leaks is tiny and doesn't grow during the lifetime of the process.
  • The memory returned to the system as soon as the process terminates anyway.
  • Since the leaks are in code beyond your control, there's not a huge amount you can do. You could fix them and use your own version of the VCL units in question, but is it worth it?

The only time these leaks could matter is if you had a DLL which was loaded and unloaded from the same process thousands of times during the lifetime of that process. I don't believe this is a very realistic scenario.

If you don't register the leaks then the FastMM leak reporting becomes largely ineffective because it shows every time. If it shows every time you learn to ignore it. This leak reporting is very valuable, but it is only valuable if it shows leaks that you have some control over.

In my Delphi 6 project I have the following code in my .dpr file:

// Register expected VCL memory leaks caused by Delphi unit HelpIntfs.
FastMM4.RegisterExpectedMemoryLeak(36, 2); // THelpManager x 1, THTMLHelpViewer x 1
FastMM4.RegisterExpectedMemoryLeak(20, 7); // TObjectList x 3, THelpSelector x 1, Unknown x 3
FastMM4.RegisterExpectedMemoryLeak(52);    // TWinHelpViewer x 1

I also have the following in a TForm descendant from which all forms in my app descend:

var
  ExpectedHelpStringMemoryLeakRegistered: Boolean;

procedure TMyForm.WMHelp(var Message: TWMHelp);
begin
  if not (biHelp in BorderIcons) and not ExpectedHelpStringMemoryLeakRegistered then begin
    // Register expected VCL memory leaks caused by Delphi unit HelpIntfs.
    FastMM4.RegisterExpectedMemoryLeak(44); // TString x 1
    ExpectedHelpStringMemoryLeakRegistered := True;
  end;
  inherited;
end;

Depending on exactly which units you use in the RTL/VCL and how you use them, you may need to register different memory leaks.

风和你 2024-10-24 02:43:49

我猜这是正常的,除非你修补了源代码。 IIRC,当出现“memproof”时,其作者“Atanas Stoyanov”保留了导致内存泄漏的错误列表。 “classes.pas”fi 中的泄漏影响了每个 VCL 表单应用程序。尽管该产品已不存在,但您可以在“自动化 QA”网站上找到该列表。这是D6 列表

I would guess it is normal unless you patched the sources. IIRC, when there was 'memproof', its author 'Atanas Stoyanov' kept a list of bugs that caused memory leaks. The leak in the 'classes.pas', f.i., effected every VCL forms application. Though the product does not exist anymore, you can find the list at 'Automated QA's site. Here's the list for D6.

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