FastMM4,Delphi6,TApplication泄漏? [英] FastMM4, Delphi6, Leak of TApplication?

查看:200
本文介绍了FastMM4,Delphi6,TApplication泄漏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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


泄漏的内存。
小块漏洞是(不包括由指针注册的
预期泄漏):

13 - 20字节:TObjectList x 3,
未知x 3 29 - 36字节:
TWinHelpViewer x 1 37 - 52字节:
THelpManager x 1


这是正常的吗?



这是什么原因造成的?



感谢:
dd

解决方案

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



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


  • 这些已知VCL泄漏的泄漏内存很小,在进程的生命周期内增长。


  • 由于泄漏在代码中,因此只要进程终止,内存就会返回到系统。超出你的控制范围,你可以做的事情并不多。你可以修复它们并使用你自己版本的VCL单元,但它是否值得?



唯一一次这些泄漏可能很重要的是,如果您有一个在该进程的生命周期中从同一进程加载和卸载数千次的DLL。我不相信这是一个非常现实的情况。



如果您没有注册泄漏信息,FastMM泄漏报告将变得无效,因为它每次都会显示。如果它显示每次你学会忽略它。这个泄漏报告是非常有价值的,但它是唯一有价值的,如果它显示泄漏,你有一定的控制。

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

  //注册Delphi单元HelpIntfs引起的预期VCL内存泄漏。 
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
$ b $ $ $
ExpectedHelpStringMemoryLeakRegistered:Boolean; code $> code $>后裔,我的应用程序中的所有表单都下降了:



procedure TMyForm.WMHelp(var Message:TWMHelp);
开始
如果不是(在BorderIcons中是biHelp)而不是ExpectedHelpStringMemoryLeakRegistered,则开始
//注册由Delphi单元HelpIntfs引起的预期VCL内存泄漏。
FastMM4.RegisterExpectedMemoryLeak(44); // TString x 1
ExpectedHelpStringMemoryLeakRegistered:= True;
end;
继承;
end;

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


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

解决方案

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.

这篇关于FastMM4,Delphi6,TApplication泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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