FastMM4,如何读取日志文件?

4
我正在开发一款软件,因此我刚刚开始在我的项目中使用FastMM4。
我在网上找到了如何获取FastMM4中的“行号”的信息,我已经得到了行号,但是我不知道日志中的其他信息是什么意思?
日志文件中包含以下内容:
This block was allocated by thread 0x15F8, and the stack trace (return addresses) at     the time was:
402E86 [system.pas][System][System.@GetMem][2648]
403A3B [system.pas][System][System.TObject.NewInstance][8824]
403DAA [system.pas][System][System.@ClassCreate][9489]
403A70 [system.pas][System][System.TObject.Create][8839]
46A257 [u_home.pas][u_home][u_home.TForm1.SpeedButton1Click][80] {<-memory leak is here, but what are the Other detections?}
443AAC [Controls.pas][Controls][Controls.TControl.Click][5226]
46958B [Buttons.pas][Buttons][Buttons.TSpeedButton.Click][1211]
46956B [Buttons.pas][Buttons][Buttons.TSpeedButton.MouseUp][1204]
443FB2 [Controls.pas][Controls][Controls.TControl.DoMouseUp][5352]
441BA0 [Controls.pas][Controls][Controls.TControl.SetMouseCapture][4379]
444042 [Controls.pas][Controls][Controls.TControl.WMLButtonUp][5364]

The block is currently used for an object of class: TStringList

The allocation number is: 440

在这种情况下,leak是泄漏的意思。
   46A257 [u_home.pas][u_home][u_home.TForm1.SpeedButton1Click][80] {<-memory leak is here, but what are the Other detections?}

我的代码

 procedure TForm1.SpeedButton1Click(Sender: TObject);
  var
  str : TStringList;
  begin
  str := TStringList.Create;  {<--im not freeing the, so leak}

  end;

输入图像描述

这里是调用栈 输入图像描述

我在网上搜索了,但我不知道其他的检测方法...

402E86 [system.pas][System][System.@GetMem][2648]
403A3B [system.pas][System][System.TObject.NewInstance][8824]
403DAA [system.pas][System][System.@ClassCreate][9489]
403A70 [system.pas][System][System.TObject.Create][8839]

{Other then this}
46A257 [u_home.pas][u_home][u_home.TForm1.SpeedButton1Click][80] {<-memory leak is here, but what are the Other detections?}
{Other then this}

443AAC [Controls.pas][Controls][Controls.TControl.Click][5226]
46958B [Buttons.pas][Buttons][Buttons.TSpeedButton.Click][1211]
46956B [Buttons.pas][Buttons][Buttons.TSpeedButton.MouseUp][1204]
443FB2 [Controls.pas][Controls][Controls.TControl.DoMouseUp][5352]
441BA0 [Controls.pas][Controls][Controls.TControl.SetMouseCapture][4379]
444042 [Controls.pas][Controls][Controls.TControl.WMLButtonUp][5364]

我正在使用Delphi 2006

我也尝试在Delphi 6、Delphi 7中打开并尝试了同样的内容。

检查过后,我发现这与FastMM$检测和注册一些已经存在于Delphi中的泄漏有关。以下是相关链接:如何跟踪FastMM引起的棘手内存泄漏?,以及用于注册泄漏的链接:使用FastMM4,如何注册泄漏的字符串?

此外,还有这个链接:FastMM4、Delphi6、TApplication泄漏?

它们只是导致内存泄漏的步骤吗?

2个回答

6

您在日志中看到的是导致内存泄漏的调用堆栈。

您可以在问题的调用堆栈中看到其有多有用。想象一下,如果您只有顶部行,即导致泄漏的调用

402E86 [system.pas][System][System.@GetMem][2648]

仅凭这些信息是无法确定问题的,因为所有堆分配都通过GetMem进行。需要查看调用栈以确定导致调用GetMem的原因,并找到引起泄漏的根本原因。


+1,好的,简而言之,它们是“步骤”,它们会导致内存泄漏。 - PresleyDias
有没有一种方法只显示/获取单元名称、类名和行号,就像这样 46A257 [u_home.pas][u_home][u_home.TForm1.SpeedButton1Click][80] - PresleyDias
我不理解那个最后的问题。 - David Heffernan
我的意思是,FastMM4中是否有一个设置,只记录发生泄漏的单元?就像在我的情况下 46A257 [u_home.pas][u_home][u_home.TForm1.SpeedButton1Click][80] - PresleyDias
FastMM 无法确定是哪个单元。这取决于您。 - David Heffernan

5

FastMM无法猜测代码背后的意图,并确定哪个指令导致了需要对应释放内存的内存分配。

请记住,FastMM仅记录在您的代码执行期间进行的所有内存分配。
它不知道泄漏发生的原因、方式或位置,只知道在应用程序关闭时您尚未释放此特定分配,而一切都应该是干净的。

因此,当报告泄漏时,实际上显示的是一个分配。
FastMM不知道您的应用程序,只能显示导致该特定代码点(通常是数百万个GetMem调用之一)分配内存的整个调用链。
有意义的信息可以通过向上追溯直到找到需要一些内存的较高级别指令(例如TButton.Create)并查看该特定按钮是否已被释放(泄漏其所有内容),或者像TMyBadButton.Create这样创建某些AltBitmap但从未释放它来找到。
在一种情况下,泄漏位于创建并未释放的按钮的应用程序代码中,在另一种情况下,则位于TMyBadButton组件代码中。

更新: 您可能会发现这个旧的CodeRage会话《内存泄漏入门》很有用。


有没有人有《CodeRage内存泄漏入门》的镜像?@francois的链接不存在了。 - sybond
糟糕,我的错。它被我的办公室代理阻止了。切换到Tor网络,下载正在进行中..感谢@François。 - sybond
很遗憾,那个文件不再可用了,codegear.com 是一个已经失效的域名。 - UnDiUdin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接