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 4616564
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:59:57+00:00 2026-05-22T01:59:57+00:00

With FastMM4 one can easily register a leaked pointer, but not a leaked string.

  • 0

With FastMM4 one can easily register a leaked pointer, but not a leaked string. Apparently the @ operator applied to a string is not really giving us the whole string, nor is PChar(string); What can I use to nicely register a leaked string?

For now I found this works:

FastMM4.RegisterExpectedMemoryLeak(Pointer(NativeInt(PChar(StringVariable))-12));

But it relies on the magic number 12, and that’s version-dependent, and the code really doesn’t express what’s going on. I hope there’s a RTL function somewhere that takes a string and gives back a pointer to the “base” of the string, or some FastMM4 method that I overlooked.

I can pack that ugly beast of expression in a procedure like this, but I still find it hacky:

procedure RegisterExpectedStringLeak(const s:string);
begin
  {$IFDEF VER210}
  FastMM4.RegisterExpectedMemoryLeak(Pointer(NativeInt(PChar(s))-12));
  {$ELSE}
  {$MESSAGE Fatal 'This only works on Delphi 2010'}
  {$ENDIF}
end;

This should be irrelevant for the question. Here’s why I’m leaking strings:

I’m using a caching mechanism to store certain pieces of data for the life of the application. I do not intend to free those objects, because I do need them for the life of the application and going through proper finalization only waists time at application shutdown. Those objects contain some string fields, so obviously those strings are “leaked”.

  • 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-05-22T01:59:58+00:00Added an answer on May 22, 2026 at 1:59 am

    The closest I can think of would be:

    function RegisterExpectedStringLeak(const S: string): Boolean;
      type
        {Have to redeclare StrRec here, because it is not in the interface section of system.pas}
        PStrRec = ^StrRec;
        StrRec = packed record
          {$ifdef CONDITIONALEXPRESSIONS}
          {$if RTLVersion >= 20}
          codePage: Word;
          elemSize: Word;
          {$ifend}
          {$endif}
          refCnt: Longint;
          length: Longint;
        end;
    begin
      Result := RegisterExpectedMemoryLeak(Pointer(NativeInt(PChar(S)) - SizeOf(StrRec)));
    end;
    

    The re-declaration of StrRec is copied from Delphi XE’s getmem.inc (FastMM4) – I only added the {$ifdef CONDITIONALEXPRESSIONS}. I think it should be backwards-compatible with older versions of Delphi, too.

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

Sidebar

Related Questions

How can I list all instantiated objects in all application, using FASTMM4 or default
I have just used FastMM4 to detect leaks. I did not realise our application
Quick one; am I right in thinking that passing a string to a method
I am using Delphi 2009 which has the FastMM4 memory manager built into it.
Quick one I hope - I'm just about to delve into a Delphi 5
I have a Delphi Apache Shared Module. The base class is TWebModule. I can
I'm developing some plugins to my application using the JEDI Plugin tecnology, but I
I know how to get the System memory use using GlobalMemoryStatusEx, but that tells
I'm using the command line compiler for builds. One problem I see is that
I checked the FastMM4 with D6. When I debug a simple application with uses

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.