[fpc-pascal] FillChar/FillByte and Finalize()
Krzysztof
dibo20 at wp.pl
Tue Mar 15 23:47:50 CET 2016
Indeed! This code need finalize() now because heaptrc detect memory leak:
procedure TForm1.Button1Click(Sender: TObject);
var f: TMyRec;
begin
FillChar(f, SizeOf(TMyRec), 0);
f.Field1 := 123;
f.Field2 := 'abc'+IntToStr(f.Field1);
push(@f);
system.Finalize(f);
FillChar(f, SizeOf(TMyRec), 0);
f.Field1 := 456;
f.Field2 := 'vbnj'+IntToStr(f.Field1);
push(@f);
end;
Although, leak is only when FillChar is called again. For example this is
not leak:
procedure TForm1.Button1Click(Sender: TObject);
var f: TMyRec;
begin
FillChar(f, SizeOf(TMyRec), 0);
f.Field1 := 123;
f.Field2 := 'abc'+IntToStr(f.Field1);
push(@f);
f.Field1 := 456;
f.Field2 := 'vbnj'+IntToStr(f.Field1);
push(@f);
f.Field1 := 789;
f.Field2 := 'zzzz'+IntToStr(f.Field1);
push(@f);
end;
Thanks Olivier for explanation
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20160315/7af34352/attachment.html>
More information about the fpc-pascal
mailing list