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:
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;