IceCold
IceCold

Reputation: 21124

Why are memory leaks reported for Indy 10?

I have this leak in Indy 10.5.7 (under Delphi 7).

5 - 12 bytes: TIdThreadSafeInteger x 1
21 - 36 bytes: TIdCriticalSection x 2


I use Indy like this:

function getWeb(a,b:Integer):Integer;
var url: string;
    H: TIdHttp;
    SS: TStringStream;
begin
  url := 'http://blabla';
  H := TIdHttp.Create(nil);
  try
    SS := TStringStream.Create('');
    try
      H.Get(url, SS);
      Result := StrToInt(SS.DataString);
    FINALLY
     SS.Free;
    END;
  finally H.Free;
  end;

The leak itself doesn't bother me since is on app shutdown. That makes my melon explode is the error message I see every time I shut down the app.

Why this leak appear?


I have checked the Indy web site but it barely makes sense. Anyway, it looks this bug cannot be fixed: the latest version of Indy cannot be compiled with Delphi 7. The only solution might be Indy 9. Update: it looks like what on the web site calls v10.203 is is actually v10.2.3.

Upvotes: 4

Views: 3629

Answers (3)

Junior
Junior

Reputation: 21

There is a IdStack validation file which does not pass through the cleaning function.

Open the file IdStack.pas

At the end of the file, look for this:

{$ IFNDEF DOTNET}  
   {$ IFDEF} REGISTER_EXPECTED_MEMORY_LEAK
      IndyRegisterExpectedMemoryLeak (GStackCriticalSection); 
   {$ ENDIF} 
{$ ENDIF} 

finalization 

    // Dont Free. If shutdown is from another Init section, it can cause GPF When stack 
    // Tries to access it. App will kill it off anyways, so just let it leak 

    // # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    // THIS LINE AND INCLUDE A COMMENT LINE DOWN 
    if GStackCriticalSection <> nil then FreeAndNil (GStackCriticalSection);
    // # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

    {$ IFDEF} FREE_ON_FINAL 
    // # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    // FreeAndNil (GStackCriticalSection); // DISABLE THIS LINE
    // # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    {$ ENDIF} 

    end. 

I'm using version 10.515 from Indy, you can find this version for download at http://indy.fulgan.com/ZIP/

Upvotes: 2

Junior
Junior

Reputation: 21

to remove other message includes this command in the main DPR

Application.terminate; 
if GThreadCount <> Nil then GThreadCount.Free; 

Add IdThread uses.

Even more!

Upvotes: 0

Brian Frost
Brian Frost

Reputation: 13454

This is a problem that occurs with FastMM memory manager and has been around for a while and there is a lot of information available on fixes. The solution I use in Delphi 2010 is:

  1. Make the changes below to the file IdGlobal.pas
  2. Add the path "C:\Program Files\Embarcadero\RAD Studio\7.0\source\Indy\Indy10\System" (without quotes) to the library.

Changes:

{$IFNDEF DOTNET}
  {$IFDEF REGISTER_EXPECTED_MEMORY_LEAK}
function IndyRegisterExpectedMemoryLeak(AAddress: Pointer): Boolean;
{$IFDEF USEINLINE}inline;{$ENDIF}
begin

  // ===== My modification begins =====================

    Result := FastMM4.RegisterExpectedMemoryLeak(AAddress);
    Exit;


  // ===== My modification ends =====================

Hope this helps.

Upvotes: 5

Related Questions