2017-06-16 34 views
0

看来,设置ReportMemoryLeaksOnShutdown := true不会对用Delphi 10.2东东创建的程序有任何影响(我在Windows和Linux程序中试过)。即使有明显的内存泄漏,也没有任何报道。“ReportMemoryLeaksOnShutdown”不能在Delphi 10.2东京工作?

有人可以证实这一点吗?有没有其他方法来检查Linux程序中的内存泄漏?在Windows上,我可以使用madExcept。

------------------编辑2 ------------------

在Delphi 10.2 ReportMemoryLeaksOnShutdown := true似乎只适用于未标记为控制台应用程序的程序。一旦我注释掉行{$APPTYPE CONSOLE}我收到所需的错误信息(当我在Windows上运行该程序)。

------------------编辑1 ------------------

这是请求的示例:

program WeakRefTest; 

{$APPTYPE CONSOLE} 

{$R *.res} 

uses 
    SysUtils; 

type 
    TParent = class; 

    TChild = class 
     private 
     {$IFDEF AUTOREFCOUNT} [Weak] {$ENDIF} 
     Parent: TParent; 
     public 
     constructor Create (const Parent: TParent); 
     destructor Destroy; override; 
    end; { TChild } 

    TParent = class 
     private 
     Child : TChild; 
     public 
     constructor Create; 
     destructor Destroy; override; 
    end; { TParent } 

constructor TChild.Create(const Parent: TParent); 
begin 
    inherited Create; 

    WriteLn ('TChild.Create'); 
    Self.Parent := Parent; 
end; 

destructor TChild.Destroy; 
begin 
    WriteLn ('TChild.Destroy'); 
    inherited; 
end; 

constructor TParent.Create; 
begin 
    inherited; 

    WriteLn ('TParent.Create'); 
    Child := TChild.Create (Self); 
end; 

destructor TParent.Destroy; 
begin 
    WriteLn ('TParent.Destroy'); 
    inherited; 
end; 

procedure SubRoutine; 

var 
    Parent : TParent; 

begin 
    Parent := TParent.Create; 
    WriteLn ('"SubRoutine" exit'); 
end; { SubRoutine } 

begin { WeakRefTest } 
    ReportMemoryLeaksOnShutdown := true; 

    try 
     SubRoutine; 
     WriteLn ('"WeakRefTest" done'); 

    except 
     on E: Exception do 
      WriteLn (E.ClassName, ': ', E.Message); 
    end; 
end. 

要强制在Linux上注释掉在的TChild声明的[Weak]属性就行了内存泄漏。当编译Windows时,会有内存泄漏,因为ARC不受支持。

当我编译并采用Delphi XE出现一则消息,有内存泄漏运行代码: Message displayed when compiled with Delphi XE

当我编译并采用Delphi 10.2没事的Windows运行出现了。我在TChild的声明中注释掉[Weak]属性后,使用Linux编译器时也是如此。

+0

提交(在Windows FMX项目)Embarcadero公司 –

+0

我只是测试一个bug报告,它工作正常。你能举一个例子吗? – Dsm

+0

您应该用[mcve] –

回答

4

如果您从cmd窗口运行控制台应用程序,它将显示有关内存泄漏的相应消息。 内存泄漏报告的行为已更改,并且窗口应用程序显示MessageBox,而控制台应用程序在控制台中获取消息。

在Delphi XE2中,ScanForMemoryLeaks过程中有单个MessageBoxA。 在Delphi 10.2中有自定义过程ShowMessage(AMessage,ATitle:_PansiChr);它调用WriteConsoleFile或MessageBoxA。 所以它的设计,而不是错误(恕我直言)。

比较讨论:Reporting memory leaks on shutdown with a console application

+0

感谢您澄清这一点。从我的角度来看,这并没有得到适当的考虑,但现在我知道是什么导致了这种行为,我总是可以使用[FastMM4](https://github.com/pleriche/FastMM4)或使用'ExitProcessProc'as描述[这里](https://stackoverflow.com/questions/39579740/reporting-memory-leaks-on-shutdown-with-a-console-application)。 –

相关问题