Heap dump by heaptrc unit
106 memory blocks allocated : 2574/2696
105 memory blocks freed : 2558/2680
1 unfreed memory blocks : 16
True heap size : 393216
True free heap : 393120
Should be : 393136
Call trace for block $76F6E180 size 16
$00010284 HAVE_LEAK, line 31 of test_const_rec.pas
$000103EC main, line 52 of test_const_rec.pas
If you make DataRecord a global const, you can ensure that its string field (managed memory) is finalized.Yes. In producing program i have make global const and leak is go away.
Remark: It should be stressed that typed constants are automatically initialized at program start. This is also true for local typed constants and initialized variables. Local typed constants are also initialized at program start. If their value was changed during previous invocations of the function, they will retain their changed value, i.e. they are not initialized each time the function is invoked.I think that say when program start for typed const is called "initialize". Is no help read "Finalize" typed const.
A simpler example of a memory leak:Thanksy. Yes, that much more simple
...
In my opinion, this is a compiler bug. In Delphi, this code does not cause a memory leak.I think same.
Remark: It should be stressed that typed constants are automatically initialized at program start. This is also true for local typed constants and initialized variables. Local typed constants are also initialized at program start. If their value was changed during previous invocations of the function, they will retain their changed value, i.e. they are not initialized each time the function is invoked.I think than can write sentence after:
A simpler example of a memory leak:In my opinion too.. see also here: https://forum.lazarus.freepascal.org/index.php?topic=44552.0In my opinion, this is a compiler bug. In Delphi, this code does not cause a memory leak.
{$MODE OBJFPC} {$WRITEABLECONST ON} {$LONGSTRINGS ON} procedure Test; const Leak: string = 'Some string'; begin UniqueString(Leak); end; begin Test; end.
Hmm, it seems that the compiler does not generate the finalizer for the unit (or program) if there are only local constants. If I add a global constant then the finalizer is generated for both the global constant and the local one. :(Maybe i no read correct (then i sorry). If make add:
const
SomeConst = 'some thing';
....
Then have leak no remove example my. Then you write no correct ? I write maybe important i test freepascal release 3.0.4Please file a bug, preferably with the example by ASerge.If is bug then i can ask some one can maybe make report bug ? I make very bad english write.