Учитывая следующий код Delphi, Foo
is Free
'd on FormClose
, но TFoo.Destroy
не вызывается, и поэтому Bar
не является Free
'd, что приводит к утечке памяти?
Я что-то пропустил или Foo.Free не должен вызывать Foo.Destroy в какой-то момент?
type
TBar = class
SomeInteger : integer;
end;
TFoo = class
Bar : TBar;
constructor Create();
destructor Destroy();
end;
var
Foo : TFoo;
implementation
constructor TFoo.Create;
begin
Bar := TBar.Create;
Bar.SomeInteger := 2;
end;
destructor TFoo.Destroy;
begin
Bar.Free;
Bar := nil;
showmessage('Destroyed!');
end;
procedure TForm10.FormCreate(Sender: TObject);
begin
Foo := TFoo.Create;
showmessage('Foo created');
end;
procedure TForm10.FormDestroy(Sender: TObject);
begin
Foo.Free;
Foo := nil;
end;