Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8677807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:33:28+00:00 2026-06-12T20:33:28+00:00

In Delphi , I usually write a simple leak test like this: program MemLeak;

  • 0

In Delphi, I usually write a simple leak test like this:

program MemLeak;

{$APPTYPE CONSOLE}

uses
    SysUtils;

procedure Leak;
begin
    { Put leaking code here. }
end;

begin
    ReportMemoryLeaksOnShutdown:= True;
    try
        Leak;
    except
        on E: Exception do
            Writeln(E.ClassName, ': ', E.Message);
    end;
end.

How do I detect memory leaks in Free Pascal/Lazarus?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:33:29+00:00Added an answer on June 12, 2026 at 8:33 pm

    Free Pascal has a similar feature. At the end of the program, call DumpHeap, or enable the heaptrc option in the Lazarus project settings. The output file can be set with the SetHeapTraceOutput method. Both methods are in the unit heaptrc which must be the first in the project (to capture allocations from start).

    More information:

    • http://www.freepascal.org/docs-html/rtl/heaptrc/usage.html
    • http://www.freepascal.org/docs-html/rtl/heaptrc/environment.html

    Leak visualization: the Lazarus package “LeakView” presents the content of a heap trace output file in a tree view. It is included in the default installation and available after a rebuild of the IDE. (not yet tested by me)

      // By default information is written to standard output, 
      // this function allows you to redirect the information to a file
      SetHeapTraceOutput('heaptrace.log');
    
      // normally the heap dump will be written automatically at the end,
      // but can also be written on demand any time   
      DumpHeap;
    

    The output looks like:

    C:\path\to\Demo.exe 
    Heap dump by heaptrc unit
    244 memory blocks allocated : 8305/9080
    241 memory blocks freed     : 8237/9000
    3 unfreed memory blocks : 68
    True heap size : 458752
    True free heap : 458288
    Should be : 458480
    Call trace for block $0010CE58 size 28
      $0044ACCB  TIDTHREADSAFE__CREATE,  line 226 of C:/path/to/indy-10.5.8.tiburon/Lib/Core/IdThreadSafe.pas
      $00444245  IDTHREAD_init,  line 641 of C:/path/to/indy-10.5.8.tiburon/Lib/Core/IdThread.pas
      $00409D74
      $0040E1A1
      ...
    

    (tested with Free Pascal 2.6.0)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With Delphi for Windows, I usually use this code: function isCtrlDown : Boolean; var
Finding dead code in Delphi is usually real simple: just compile and then scan
I have an application written in Delphi 6 and compiled on Windows XP. Usually
Delphi 2006, whenever started afresh, loses component package. This happens on a daily bases.
Is there any in modern Delphi versions? (I've seen TWordApplication in Delphi 7) Usually
We've got an application written in Delphi that uses Delphi On Rails and acts
Delphi Xe2. Listview (Lv1) with the big list items. Lv1 have standart compare procedure
This question involves Delphi and XE specifically deprecating Suspend and Resume. I have read
I am using Delphi 2009. I have a very simple data structure, with 2
Delphi 2010 & Oracle Database I need to write a select statement across two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.