Memory corruption ("modified after freed") in TTMSFNCDataGridRenderer when TTMSFNCDataGrid is destroyed as a nested child (e.g. closing a form/frame that contains the grid)

Hello,

Version: tms.fnc.uipack:7.3.1.5
IDE: RAD Studio 13 Florence (37.0) Platform: Win32,
Debug build Memory manager: FastMM5 (FullDebugMode)

FastMM5 in FullDebugMode consistently reports "A memory block was modified after it was freed" for the internal TTMSFNCDataGridRenderer object (the lazily-created "Root"/persistence renderer returned by TTMSFNCDataGridBase.GetPersistenceRenderer/GetRoot). This has been 100% reproducible for us for about two weeks, across multiple independent screens, every time a form/frame containing a TTMSFNCDataGrid is closed and the grid is destroyed as part of the parent's DeleteChildren cascade.
The corrupted block is always 2370-2400 bytes, and the modification is always detected at the same relative offset (offset 400, length 4 bytes) — i.e. it looks like a specific field inside the renderer (created alongside a TTMSFNCCustomGraphicsStroke instance during the renderer's Create) is still being written to after the renderer itself has already been freed.
Context / how it's triggered on our side
The grid is a normal design-time TTMSFNCDataGrid dropped on an FMX frame (bound through a TTMSFNCDataGridDatabaseAdapter + TDataSource), nested a couple of layout levels deep inside a TGridPanelLayout (our base "activity frame"). The grid is not touched by any custom code at destroy time in this scenario — it's destroyed purely as a consequence of the owning frame being closed/freed (TFmxObject.DoDeleteChildren walking down through TGridPanelLayout → the grid's own Destroy). No custom Adapter/DataSource handling is involved in this particular reproduction.
We also reproduced the same signature with a grid created dynamically at runtime (via our own helper, with an explicit TTMSFNCDataGridDatabaseAdapter), so it does not appear to be specific to design-time-streamed grids either.
FastMM5 log excerpt (most recent occurrence, 2026-10-28 10:03:11)
<> UnknownCopy Code

A memory block was modified after it was freed.
The block size is 2396.
Modifications were detected at offsets (with lengths in brackets): 400(4).

The block was allocated on 2026-10-28 10:02:47.696, stack trace at allocation time:
FastMM_DebugGetMem_GetDebugBlock
FastMM_DebugGetMem
@GetMem
TObject.NewInstance
@ClassCreate
FMX.TMSFNCDataGridRenderer.TTMSFNCDataGridRenderer.Create (line 9644)
FMX.TMSFNCGraphicsTypes.TTMSFNCCustomGraphicsStroke.Create (line 2962)
@AfterConstruction
@AfterConstruction
FMX.TMSFNCDataGridBase.TTMSFNCDataGridBase.GetPersistenceRenderer (line 389)
FMX.TMSFNCDataGridBase.TTMSFNCDataGridBase.GetRoot (line 404)
FMX.TMSFNCDataGrid.TTMSFNCCustomDataGrid.Create (line 8049)
System.Classes.CreateComponent (line 11875)
System.Classes.TReader.ReadComponent (line 11921)
System.Classes.TReader.ReadDataInner (line 11987)
System.Classes.TReader.ReadData (line 11972)

This block was freed by the same thread, stack trace at free time:
FastMM_FreeMem_FreeDebugBlock
FastMM_DebugFreeMem
@FreeMem
TObject.FreeInstance
@ClassDestroy
FMX.TMSFNCDataGridRenderer.TTMSFNCDataGridRenderer.Destroy (line 11527)
TObject.Free
FMX.TMSFNCDataGridBase.TTMSFNCDataGridBase.Destroy (line 283) // FreeAndNil(FRoot)
FMX.TMSFNCDataGrid.TTMSFNCCustomDataGrid.Destroy (line 8958)
FMX.Types.TFmxObject.DoDeleteChildren (line 4853)
FMX.Controls.TControl.DoDeleteChildren (line 2121)
FMX.Types.TFmxObject.DeleteChildren (line 4868)
FMX.Types.TFmxObject.Destroy (line 4356)
FMX.Controls.TControl.Destroy (line 2152)
TObject.Free
FMX.Types.TFmxObject.DoDeleteChildren (line 4853)
FMX.Controls.TControl.DoDeleteChildren (line 2121)
FMX.Layouts.TGridPanelLayout.DoDeleteChildren (line 4296)

The allocation number is: 2089637

We have 15 occurrences of this exact same pattern logged over two weeks, always at offset 400, always length 4, always this same allocation/free call chain (only the grid instance/screen differs).

Hi Tiberiu,

Thank you for the detailed FastMM5 log. The fixed offset made this easy to pin down.

Offset 400 in the renderer is its reference to the data adapter. When a form or frame closes, the grid is destroyed as a child control first, and the TTMSFNCDataGridDatabaseAdapter is freed afterwards as an owned component. The grid cleared its own reference to the adapter, but not the adapter's reference back to the grid's data. When the adapter was freed, its destructor reset that reference inside the grid's already freed internal renderer: the 4 bytes FastMM reports.

This is fixed: the grid now detaches the adapter when it is destroyed. The fix will be included in the next TMS FNC UI Pack update.

Until then, free the adapter before the grid, for example in the form's OnDestroy event, or in the frame's destructor before inherited:

destructor TMyFrame.Destroy;
begin
FreeAndNil(TMSFNCDataGridDatabaseAdapter1);
inherited;
end;

For a grid created at run time, free the adapter before the grid in the same way.