FastMM4 says: "The block header is damaged."

I had this unpleasant mistake, which disappeared in the past, but after a while it returned.

I have two TSam objects (derived from TPersistent) created and loaded into a TAsmJob object (obtained from TObjectList).

At run time, the form creates a TStringGrid, and then AsmJob, which creates the two SAM objects (and loads some data from the disk in each of them). AsmJob is also assigned to the grid. When the form is destroyed, the grid takes care of AsmJob, freeing it, which frees up TSAM objects. Here's the problem: the first object is freed without problems, and the second dies when its inherited method is called (in the Destroy destructor).

I use FreeAndNil throughout the program to free objects. TSAM objects are not NIL !!!!! So this is the first attempt to free objects. Even the data inside the objects is consistent.

The backbone of the program is as follows:

**Create:**

Form -> StringGrid
     -> AsmJob -> Sam1, Sam2
StringGrid.AsmJob:= AsmJob;


**Free:**

Form -> StringGrid -> AsmJob -> Sam1, Sam2

I really don't understand where I am trying to double or overwrite an object AFTER it was released.


edit:

Some of the errors I received are:

  • FastMM detected an error during a free block scan operation. FastMM detected that the block was upon release.

  • FastMM detected an error during a free block scan operation. The block header is damaged.

More details:

The current thread ID is 0x19C, and the stack trace (return addresses) leading to this error is: 
402E77 [System][@FreeMem] 
4068DC [System][@DynArrayClear] 
405E2D [System][@FinalizeArray] 
405D31 [System][@FinalizeRecord] 
40432F [System][TObject.CleanupInstance] 
404272 [System][TObject.FreeInstance] 
404641 [System][@ClassDestroy] 
4D313E [UnitSam.pas][TSam.Destroy][297] 
4042BF [System][TObject.Free] 
4149ED [SysUtils][FreeAndNil] 
4D9C0A [UnitAsmJob.pas][UnitAsmJob][TAsmJob.Destroy][180]  

"", IDE, " ". , FastMM4 . FastMM - , , . () , FastMM.


:

. , , .

. , . , :) , TSAM . . . TSam , () , TSam. TStringGrid TSam, .

: , , , ? ?


" AsmJob TStringGrid, TStringGrid AsmJob, ?"

MyGrid = TStringGrid
  public 
    AsmJob: TAsmJob; 
  end; 

- TForm.Create(, Grid),

MyGrid.AsmJob=AsmJob; 

MyGrid :

begin 
  FreeAndNil(AsmJob); 
  inherited 
end;
+5
4

, . , . - . . .

" " ( Build, ) FastMM ( CheckHeapForCorruption, CatchUseOfFreedInterfaces DetectMMOperationsAfterUninstall).

FullDebugModeScanMemoryPoolBeforeEveryOperation, , . LOT.

, ScanMemoryPoolForCorruptions . . ? . ? . ? - . FullDebugModeScanMemoryPoolBeforeEveryOperation, . .

: "FastMM , ". , , ( " " ).

, ​​! , FastMM , ( , ): " / unallocated block".

+12

, , , - , , - . ? , , . .

+4

- , , . NULL- IPC ( ..), , .

- , .

+2

, , .

:

procedure TForm1.FormCreate(Sender: TObject);
var
   wObjLst : TObjectList;
begin
   wObjLst := TObjectList.Create;
   try
      wObjlst.OwnsObjects := true;
      wObjlst.Add(TPersistent.Create);
      wObjlst.Add(TPersistent.Create);
   finally
      freeandnil(wObjlst);
   end;
end;

.

,

TStringGrid, AsmJob, SAM ( ). AsmJob . , Grid AsmJob, , TSAM . : , ( Destroy ).

: AsmJob TStringGrid, TStringGrid AsmJob, ?

Secondly, why create a TObjectList descendant so that it can store two objects and then free them, rather than create them yourself, and let TObjectList destroy them, as shown above.

Another thing is to download the complete FastMM4 package from fastmm.sourceforge.net , install it, and use the fulldebug dll to track which particular object fails. You and I assume that this is one of the SAM objects, and this may or may not be.

+1
source

All Articles