The compiler does not generate finalizing code for local typed constants of a managed type

Original Reporter info from Mantis: SergeAnvarov @SergeAnvarov
  • Reporter name: Serge Anvarov

Description:

The code in the "Steps To Reproduce" cause a memory leak.
Similar code for dynamic arrays or interfaces also cause a memory leak.

Steps to reproduce:

{$MODE OBJFPC}
{$WRITEABLECONST ON}
{$LONGSTRINGS ON}

procedure Test;
const
  Leak: string = 'Some string';
begin
  UniqueString(Leak);
end;

begin
  Test;
end.

Additional information:

FPC 3.3.1 do the same.
Delphi work fine in this case.

Mantis conversion info:

  • Mantis ID: 35536
  • Version: 3.0.4
Edited by Sven/Sarah Barth