I also looked through System.pas and noticed that calling GetMem in _DynArrayCopyRange supports your analysis:
highlighted size = count * element size + 2 * Size (Longint)
. Therefore, perhaps the numbers you get from the task manager are not very accurate. You can try Pointer(someDynArray) := nil and check what size of memory leak FastMM reports for more reliable numbers.
Edit: I made a small test program:
program DynArrayLeak; {$APPTYPE CONSOLE} uses SysUtils; procedure Test; var arr: array of Integer; i: Integer; begin for i := 1 to 6 do begin SetLength(arr, i); Pointer(arr) := nil; end; end; begin ReportMemoryLeaksOnShutdown := True; Test; end.
This gives
An unexpected memory leak has occurred. The unexpected small block leaks are:
1 - 12 bytes: Unknown x 1
13 - 20 bytes: Unknown x 2
21 - 28 bytes: Unknown x 2
29 - 36 bytes: Unknown x 1
which supports 8-byte utility theory.
source share