Skip to content

Memory leak with const and dynamic array

uses
  heaptrc;

  procedure test;
  const
    ar: array of byte = nil;
  begin
    SetLength(ar, Length(ar) + 1);
    WriteLn(Length(ar));
  end;

var
  i: integer;
begin
  for i := 0 to 3 do test;
end.        

The following code creates a memory leak. Tested with Linux 64 bit. For more information follow the link to the forum.

https://www.lazarusforum.de/viewtopic.php?f=10&t=14866&hilit=array+const

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information