[fpc-pascal] Double finalize
Hairy Pixels
genericptr at gmail.com
Wed Dec 20 15:13:28 CET 2023
I feel like this was addressed but I couldn't find any references. The program below prints the following:
Initialize
Create
Finalize
Finalize
Why is Finalize called twice? I thought those were supposed to be called in pairs with initialize?
==================
{$mode objfpc}
{$modeswitch advancedrecords}
program test;
type
TManagedObject = record
class function Create: TManagedObject; static;
class operator Finalize(var self: TManagedObject); inline;
class operator Initialize(var self: TManagedObject); inline;
end;
class function TManagedObject.Create: TManagedObject;
begin
writeln('Create');
end;
class operator TManagedObject.Finalize(var self: TManagedObject);
begin
writeln('Finalize');
end;
class operator TManagedObject.Initialize(var self: TManagedObject);
begin
writeln('Initialize');
end;
begin
TManagedObject.Create;
end.
Regards,
Ryan Joseph
More information about the fpc-pascal
mailing list