Sign in Join
FPDoc Onlineexperiment

heaptrc unit

Heap debugging functionality.

This document describes the HEAPTRC unit for Free Pascal. It was written by Pierre Muller. It is system independent, and works on all supported systems.

The HEAPTRC unit can be used to debug your memory allocation/deallocation. It keeps track of the calls to getmem/freemem, and, implicitly, of New/Dispose statements.

When the program exits, or when you request it explicitly. It displays the total memory used, and then dumps a list of blocks that were allocated but not freed. It also displays where the memory was allocated.

If there are any inconsistencies, such as memory blocks being allocated or freed twice, or a memory block that is released but with wrong size, this will be displayed also.

The information that is stored/displayed can be customized using some constants.

Do not use this unit directly, instead use the -gh switch, to let the compiler insert the unit in the uses clause. You can detect whether the heaptrc unit is actually used in the main program code with the following function:

function IsHeapTraceActive : boolean;

begin
{$if declared(UseHeapTrace)}
  Result:=UseHeapTrace;
{$else}
  Result:=False;
{$endif}
end;

Classes and records

TWalkBlockInforecord

Procedures and functions

CheckHeapprocedure
CheckPointerprocedureCheck if a pointer is in the address range of the application.
DumpHeapprocedureDump memory usage report to stderr.
GetHeadSizefunction
GetKeepReleasedfunction
GetKeepReleasedBytesfunction
GetKeepReleasedPercentsfunction
GetTailSizefunction
GetTraceDepthfunction
HexDumpprocedure
SetHeadSizeprocedure
SetHeapExtraInfoprocedureStore extra information in blocks.
SetHeapTraceOutputprocedureSpecify filename or text file for heap trace output.
SetKeepReleasedprocedure
SetKeepReleasedBytesprocedure
SetKeepReleasedPercentsprocedure
SetTailSizeprocedure
SetTraceDepthprocedure
WalkHeapprocedure

Types

head_sizeproperty
KeepReleasedpropertyKeep released blocks in memory.
KeepReleasedBytesproperty
KeepReleasedPercentsproperty
tail_sizepropertySize of memory tail.
TDisplayExtraInfoProcprocedure typeThe TDisplayExtraInfoProc is a procedural type used in the call.
TFillExtraInfoProcprocedure typeThe FillExtraInfoProc is a procedural type used in the call.
TraceDepthproperty
TWalkBlockProcprocedure type

Constants

AutoCheckHeapStepconstant
GlobalSkipIfNoLeaksconstantDisable output if no leaks detected.
HaltOnErrorconstantHalt program on memory fault.
HaltOnNotReleasedconstantHalt on exit if any memory was not freed.
IncludeInternalAllocationsInStatisticsconstant
MaxLeaksToReportconstant
MaxPrintedBlockLengthconstantMaximum length of memory block dumps.
PrintFaultyBlockconstantPrint memory dump of faulty blocks ?
PrintLeakedBlockconstantPrint memory dump of leaked blocks ?
UseHeapTraceconstantIf set to False, the heap trace will be disabled.

Topics

environmenttopicControlling HeapTrc with environment variables.
usagetopicHeapTrc Usage.

An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.