Menu

Duplicate allocation number

Help
wo omla
2010-10-28
2013-05-23
  • wo omla

    wo omla - 2010-10-28

    I periodically call LogAllocatedBlocksToFile for a specifiec allocation group.
    Sometimes I see the same allocation number twice, with a different pointer and stack etc.

    Is this normal behaviour? I thought that allocation number is unique.

     
  • Pierre le Riche

    Pierre le Riche - 2010-10-29

    Hi,

    Allocation numbers are unique per process. Every time you call GetMem the number is bumped and stored in the block header. Only when you reallocate a block does it keep the old allocation number.

    Note that every time the application starts that the allocation numbers start from 0, so if you're not deleting the log file between runs you will see duplicate allocation numbers.

    Also, allocation numbers are stored in a Cardinal, so will wrap back to 0 once it hits 4 billion. It usually takes a while for that to happen though.

    Best regards,
    Pierre

     
  • wo omla

    wo omla - 2010-11-01

    Hi Pierre,

    Thanks for your answer.

    I now discovered that, although I have 'ClearLogFileOnStartup' defined, the log is cleared during initialization, not finalization. So when I call LogAllocateeBlocksToFile, I create the log file. Than during finalization, the leaks are added. This creates entries with double allocation numbers.

    When I call LogAllocatedBlocksToFile, I basically want to dump the contents to a specific file. I don't think that SetMMLogFileName is thread safe, is it?

    Thanks again.

     
  • Andrei Korshunov

    A similar problem.
    In search of memory leaks write a memory dump every 10 minutes in a separate file.
    The analysis found that blocks with numbers 4563031, 4562241, 4561344, 4561553 duplicate.

    Written by a special program for log analysis, which examines the number of consecutive log into the database.

    Recording logs do a timer in the study on memory loss program:

    procedure TFS_CL_Oper_fmMain.Timer1Timer(Sender: TObject);
    {$IFDEF LOGGING}
    var
      HostName, FName: String;
    {$ENDIF}
    begin
    {$IFDEF LOGGING}
      HostName := '';
      if Tics = 0 then
      begin
        FName := ExtractFileDir(ParamStr(0)) + '\OT_';
        If HostName <> '' then
          FName := FName + HostName + '_';
        SetMMLogFileName(PAnsiChar(AnsiString(FName + IntToStr(CurNum) + '.Txt')));
        LogAllocatedBlocksToFile(0, $ffffffff);
        Inc(CurNum);
      end else
        inc(Tics);
      if Tics >= 10 then
        Tics := 0;
      Timer1.Interval := LoggingInterval;
      if CurNum = 8 then
        Halt;
    {$ENDIF}
    end;
    

    The result can be seen, the block number 4561344 in file OT_5.Txt (IdFiles = 6) is present 2 times with different class, and in OT_6.Txt file (IdFiles = 7) taken after 10 minutes - there is only one instance of this block. To complete the picture I put the log files themselves (OT_5.Txt file in the database has IdFiles = 6, OT_6.Txt has IdFiles = 7).

    How can it be?

    PS. Delphi XE, FastMM4 4.991.

     

    Last edit: Andrei Korshunov 2017-02-15

Log in to post a comment.