Difference between revisions of "leakview"

From Lazarus wiki
Jump to navigationJump to search
m
Line 10: Line 10:
 
In your .lpr, in the beginning of your code, add
 
In your .lpr, in the beginning of your code, add
 
<syntaxhighlight>
 
<syntaxhighlight>
 +
  {$DEFINE debug}   
 +
 +
uses
 +
  ...
 +
  {$IFDEF debug}
 +
  , SysUtils
 +
  {$ENDIF}
 +
 +
...
 +
 +
begin
 
   {$IFDEF DEBUG}  
 
   {$IFDEF DEBUG}  
 
   // Assuming your build mode sets -dDEBUG in Project Options/Other when defining -gh
 
   // Assuming your build mode sets -dDEBUG in Project Options/Other when defining -gh
Line 19: Line 30:
 
   SetHeapTraceOutput('heap.trc');
 
   SetHeapTraceOutput('heap.trc');
 
   {$ENDIF DEBUG}
 
   {$ENDIF DEBUG}
 +
 +
  ...
 +
end.
 
</syntaxhighlight>
 
</syntaxhighlight>
 
to redirect the heaptrc output to file.
 
to redirect the heaptrc output to file.

Revision as of 18:56, 21 April 2014

Overview

Leakview allows fast navigation trough HeapTrc (and other?) leaks.

Usage

Leakview reads heaptrc output. For this to work, you'll need to enable heaptrc in your code:

Enabling heaptrc in Lazarus

To enable this in your Lazarus project: go to Project Options/Linking and in the Debugging section enable Use Heaptrc unit (check for mem-leaks) (-gh)

In your .lpr, in the beginning of your code, add

  {$DEFINE debug}     

uses
  ...
  {$IFDEF debug}
  , SysUtils
  {$ENDIF}

...

begin
  {$IFDEF DEBUG} 
  // Assuming your build mode sets -dDEBUG in Project Options/Other when defining -gh
  // This avoids interference when running a production/default build without -gh

  // Set up -gh output for the Leakview package:
  if FileExists('heap.trc') then
    DeleteFile('heap.trc');
  SetHeapTraceOutput('heap.trc');
  {$ENDIF DEBUG}

  ...
end.

to redirect the heaptrc output to file.

Enabling heaptrc in FPC

In FPC, you can specify -gh in your compilation option or include the heaptrc unit in your uses clause.

Then redirect the heaptrc output to file (instead of standard output). You can use similar code to the Lazarus code or alternatively, set the environment variable, e.g. on *nix:

export HEAPTRC="log=heap.trc"

or Windows:

set HEAPTRC="log=heap.trc"