2017-06-16 9 views
0

ReportMemoryLeaksOnShutdown := trueの設定は、Delphi 10.2 Tokyoで作成したプログラム(WindowsとLinuxプログラムで試したもの)には何の効果もありません。明らかなメモリリークがあっても、何も報告されません。"ReportMemoryLeaksOnShutdown"がDelphi 10.2 Tokyoで動作していませんか?

誰かがこれを確認できますか?そして、Linuxプログラムでメモリリークをチェックする別の方法がありますか? WindowsではmadExceptを使うことができました。

------------------デルファイ10.2 ReportMemoryLeaksOnShutdown := trueで編集2 ------------------

コンソールアプリケーションとしてフラグが立てられていないプログラムでのみ動作するようです。 {$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がサポートされていないのでメモリリークが発生します。私はコンパイルして10.2何も現れないのDelphiを使用して、Windows用実行すると Message displayed when compiled with Delphi XE

:私はコンパイルとDelphi XEを使用してコードを実行すると

メッセージは、メモリリークがあることが表示されます。 TChildの宣言で[Weak]属性をコメントアウトした後にLinuxコンパイラを使用した場合と同じです。

+0

は、私はちょうど(WindowsのFMXプロジェクトに)テストし、それが正常に動作しエンバカデロ –

+0

にバグレポートを提出してください。あなたは例を挙げることができますか? – Dsm

+0

[mcve] –

答えて

4

cmdウィンドウからコンソールアプリケーションを実行すると、メモリリークに関する適切なメッセージが表示されます。 メモリリークレポートの動作が変更され、ウィンドウアプリケーションのMessageBoxが表示されます。コンソールアプリケーションはコンソールでメッセージを取得します。

Delphi XE2では、ScanForMemoryLeaksプロシージャに単一のMessageBoxAがありました。 Delphi 10.2にはカスタムプロシージャShowMessage(AMessage、ATitle:_PAnsiChr)があります。 WriteConsoleFileまたはMessageBoxAを呼び出します。 それはバグ(IMHO)ではなく、設計されています。

は議論の比較:Reporting memory leaks on shutdown with a console application

+0

これを明確にしていただきありがとうございます。私の見解では、これは正しく考えられていませんでしたが、今私はいつも[FastMM4](https://github.com/pleriche/FastMM4)を使用するか、または「ExitProcessProc」を使用してこの動作の原因を知っています[ここ](https://stackoverflow.com/questions/39579740/reporting-memory-leaks-on-shutdown-with-a-console-application)に記載されています。 –

関連する問題